我对德语使用了分解器,并遵循了文档中提到的示例。到目前一切尚好。起作用了!文本kaffeetasse被标记为kaffee和tasse。
当我使用多匹配查询来查找kaffee和tasse匹配的文档时,就引起了人们的关注。在多匹配查询中,多匹配似乎使用或作为hyphenation_decompounder过滤器生成的令牌,而不是给定的运算符(“和”)。这是我的测试用例
映射
curl -XPUT "http://localhost:9200/testidx" -H 'Content-Type: application/json' -d'{ "settings": { "index": { "analysis": { "analyzer": { "index": { "type" : "custom", "tokenizer": "whitespace", "filter": [ "lowercase" ] }, "search": { "type" : "custom", "tokenizer": "whitespace", "filter": [ "lowercase", "hyph" ] } }, "filter": { "hyph": { "type": "hyphenation_decompounder", "hyphenation_patterns_path": "analysis/de_DR.xml", "word_list": ["kaffee", "zucker", "tasse"], "only_longest_match": true, "min_subword_size": 4 } } } } }, "mappings" : { "properties" : { "title" : { "type" : "text", "analyzer": "index", "search_analyzer": "search" }, "description" : { "type" : "text", "analyzer": "index", "search_analyzer": "search" } } } }' 文档id=1
curl -XPOST "http://localhost:9200/testidx/_doc/1" -H 'Content-Type: application/json' -d'{ "title" : "Kaffee", "description": "Milch Kaffee tasse"}' 文档id=2
curl -XPOST "http://localhost:9200/testidx/_doc/2" -H 'Content-Type: application/json' -d'{ "title" : "Kaffee", "description": "Latte Kaffee Becher"}' 多匹配查询
curl -XGET "http://localhost:9200/testidx/_search" -H 'Content-Type: application/json' -d'{ "query": { "multi_match": { "query": "kaffeetasse", "fields": ["title", "description"], "operator": "and", "type": "cross_fields", "analyzer": "search" } }}'我的期望是,elasticsearch应该只返回带有id=1的单个文档,因为它在其字段中有kaffee 和 tasse,但是它返回两个文档,因为它们都具有kaffee 或 tasse文本。
Elasticsearch:7.9.2
正如文档中提到的,de_DR.xml是从V1.2.zip/下载下载的。
发布于 2021-01-23 12:50:21
Elasticsearch返回两个文档,因为它将operator参数应用于原始查询 kaffeetasse,而不是应用于分析器生成的令牌kaffee和tasse。在文档 for match查询中描述的此类行为:
运算符(可选字符串)布尔逻辑,用于解释
query值中的文本。
由于原始查询是一个单词,所以operator参数没有意义。
作为一种解决方法,您可以分两个步骤执行搜索:
search分析器接收到的令牌作为multi_match查询的单词,operator参数设置为and,analyzer参数设置为whitespace (以防止已经分析的令牌再次使用search分析器进行分析):
curl -XGET "搜索“-H‘内容-类型: application/json’-d'{”查询“:{"multi_match":{”查询“:”multi_match“:”-H“,”字段“:”标题“,”描述“,”操作符“:”和“,类型:"cross_fields",”分析器“:”空格“}‘https://stackoverflow.com/questions/65826747
复制相似问题