我在 elasticsearch 中使用动态映射将我的 json 文件加载到 elasticsearch 中,如下所示:
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
def extract():
f = open('tmdb.json')
if f:
return json.loads(f.read())
movieDict = extract()
def index(movieDict={}):
for id, body in movieDict.items():
es.index(index='tmdb', id=id, doc_type='movie', body=body)
index(movieDict)
如何更新单个字段的映射?我有title
要添加不同分析器的字段。
title_settings = {"properties" : { "title": {"type" : "text", "analyzer": "english"}}}
es.indices.put_mapping(index='tmdb', body=title_settings)
这失败了。
我知道我无法更新已经存在的索引,但是重新索引从 json 文件生成的映射的正确方法是什么?我的文件有很多字段,手动创建映射/设置会很麻烦。
我可以为查询指定分析器,如下所示:
query = {"query": {
"multi_match": {
"query": userSearch, "analyzer":"english", "fields": ['title^10', 'overview']}}}
如何为索引或字段指定它?
我也可以在关闭和打开索引后将分析器设置为设置
analysis = {'settings': {'analysis': {'analyzer': 'english'}}}
es.indices.close(index='tmdb')
es.indices.put_settings(index='tmdb', body=analysis)
es.indices.open(index='tmdb')
复制英语分析仪的确切设置不会为我的数据“激活”它。
通过“激活”,我的意思是,搜索不会以英语分析器处理的形式返回,即。仍然有停用词。