gpt4 book ai didi

带有 AND 运算符的 Elasticsearch Multi-Match Query 用于 Hyphenation_decompounder token 过滤器生成的 token

转载 作者:行者123 更新时间:2023-12-04 08:13:32 24 4
gpt4 key购买 nike

我用过 hyphenation_decompounder用于德语并遵循文档中提到的示例。到现在为止还挺好。有用!。正文kaffeetasse被标记为 kaffeetasse .
当我使用 时出现了问题多匹配查询 kaffeetasse 以查找 kaffee 和 tasse 都匹配的文档。似乎多匹配使用对于由 hyphenation_decompounder 过滤器而不是多匹配查询中的给定运算符(“AND”)生成的标记。这是我的测试用例
映射

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下载自 https://sourceforge.net/projects/offo/files/offo-hyphenation/1.2/offo-hyphenation_v1.2.zip/download如文档中所述。

最佳答案

Elasticsearch 返回这两个文档,因为它适用 operator参数 到原查询 kaffeetasse , 不是 token kaffeetasse分析仪产生。此类行为在 documentation 中描述为 match询问:

operator (Optional, string) Boolean logic used to interpret text in the query value.


由于原始查询是一个词,所以 operator参数没有意义。
作为解决方法,您可以分两步执行搜索:
  • 使用 analyze API 分析您的原始查询字符串:
     curl -XGET "http://localhost:9200/testidx/_analyze" -H 'Content-Type: application/json' -d'{"analyzer": "search", "text": "kaffeetasse"}'
  • 使用从 search 收到的 token 分析器作为 multi_match 的话查询 operator参数设置为 andanalyzer参数设置为 whitespace (防止使用 search 分析器再次分析已经分析过的标记):
     curl -XGET "http://localhost:9200/testidx/_search" -H 'Content-Type: application/json' -d'{ "query": {"multi_match": {"query": "kaffee tasse", "fields": ["title", "description"], "operator": "and", "type": "cross_fields", "analyzer": "whitespace"}}}'
  • 关于带有 AND 运算符的 Elasticsearch Multi-Match Query 用于 Hyphenation_decompounder token 过滤器生成的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65826747/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com