我正在使用python和flask构建Web文本搜索。我有一个现有的数据库sqlite3.db,在我的表“Post”中,我想在“body”中搜索Blogpost索引。我正在使用sqlalchemy。

models.py

class Post(SearchableMixin, db.Model):
   __searchable__ = ['body']
   id = db.Column(db.Integer, primary_key=True)
   body = db.Column(db.String(140))

例如,主体包含ID为1、2、3和4等的“项目管理”,“工程管理”,“管理系统”和“系统工程”等。我的问题是如何在现有的sqlite数据库或mysql中创建索引或使用reindex()方法?

这是程序吗?在示例中是index ='Post'吗?
from elasticsearch import Elasticsearch
es=Elasticsearch('http://localhost:9200 ')
es.index(index='Post',doc_type='Post',id=1,body={'text':'Project Management'})
es.index(index='Post',doc_type='Post',id=2,body={'text':'Engineering Management'})
es.index(index='Post',doc_type='Post',id=3,body={'text':'Management System'})
es.index(index='Post',doc_type='Post',id=1,body={'text':'System Engineering'})

谢谢你的建议。

最佳答案

对于现有的关系数据库,为了创建索引,请转到 flask shell 终端。

Post.reindex()

并创建索引。

关于python - 在现有的sqlite关系数据库中创建Index Elasticsearch,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53270237/

10-12 01:10