【发布时间】:2019-11-18 19:01:07
【问题描述】:
我正在尝试更新其中一个索引的设置(具体来说,我想更新我的自定义分析器以使用我的自定义同义词过滤器)。我写了以下内容来更新设置,它编译没有错误,但似乎同义词过滤器没有按预期工作(我指定的同义词似乎没有效果)。我希望 Harry Potter 和 HP 是同一个东西,终结者和 TM 也是同一个东西(作为旁注,我正在关闭然后更新索引,然后再次打开它)。
client.close('movies')
client.put_settings(index='movies', body={
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"filter": "my_synonyms"
}
},
"filter": {
"custom_synonyms": {
"type": "synonym",
"synonyms": ["Harry Potter,HP => HP", "Terminator, TM => TM"]
}
}
}
}
})
client.open('movies')
这是我原来的映射索引设置:
client.create(
index = "movies",
body= {
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": "lowercase"
}
}
}
},
"mappings": {
"properties": {
"body": {
"type": "text",
"analyzer": "custom_analyzer",
"search_analyzer": "custom_analyzer",
"search_quote_analyzer": "custom_analyzer"
}
}
}
},
ignore=400
)
感谢您的帮助!
【问题讨论】:
-
你如何验证它不起作用?
-
我有一个查询电影索引的搜索查询(搜索“HP”),我正在尝试对文档进行排名,以便包含 5 次“哈利波特”的文档是顶部元素名单。现在看来,3次“HP”的文档排在首位。
-
您还应该显示您的查询。
标签: python python-3.x elasticsearch