【问题标题】:minimum_number_should_match not working in Elasticsearch New versionminimum_number_should_match 在 Elasticsearch 新版本中不起作用
【发布时间】:2021-08-21 14:48:32
【问题描述】:

大家好,我正在使用 Elastic Search 检索数据。我收到如下错误:-

{
 "error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "[bool] query does not support [minimum_number_should_match]",
            "line": 1,
            "col": 396
        }
    ],
    "type": "parsing_exception",
    "reason": "[bool] query does not support [minimum_number_should_match]",
    "line": 1,
    "col": 396
},
"status": 400
}

为此我编写了代码:

{
"_source": [
    "ch",
    "text",
    "title",
    "d_name"
],
"track_scores": true,
"sort": [
    "_score"
],
"size": 50,
"from": 0,
"query": {
    "bool": {
        "should": [
            {
                "match_phrase": {
                    "text": {
                        "query": "xxx",
                        "slop": 5
                    }
                }
            },
            {
                "match_phrase": {
                    "title": {
                        "query": "xxx",
                        "slop": 0,
                        "boost": 9
                    }
                }
            },
            {
                "match_phrase": {
                    "ch": {
                        "query": "xxxx",
                        "slop": 0,
                        "boost": 15
                    }
                }
            }
        ],
        "minimum_number_should_match": 1,
        "filter": {
            "bool": {
                "should": [
                    {
                        "term": {
                            "d_name": "The  Central"
                        }
                    }
                ]
            }
        }
    }
 }

}

它在旧版本上运行良好,但在新版本上无法运行。如果我删除“minimum_number_should_match”,那么它会给出不正确的结果,如果我使用“minimum_should_match”,那么它会给我那些找不到查询值的记录。

【问题讨论】:

  • 应该是minimum_should_match

标签: php amazon-web-services elasticsearch


【解决方案1】:

你需要使用minimum_should_match参数而不是minimum_number_should_match

更新 1:

根据下面的 cmets 搜索查询将是

{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "query": "supply",
          "fields": [
            "chapters",
            "title",
            "text"
          ]
        }
      },
      "filter": {
        "term": {
          "id": "1215"
        }
      }
    }
  }
}

【讨论】:

  • 它没有给我准确的记录。它还给出了那些“xxx”未找到的记录
  • @RajasthanAyurvedUniversity 您能否用一些示例索引数据解释您的用例,并请分享您的预期搜索结果
  • {"_source":["chapters","title","comment","text","doc","name"],"track_scores":true,"sort": [ "_score"],"size":50,"from":0,"query":{"bool":{"should":[{"match_phrase":{"text":{"query":"supply" ,"slop":3}}},{"match_phrase":{"title":{"query":"supply","slop":0,"boost":3}}},{"match_phrase":{ "chapters":{"query":"supply","slop":0,"boost":5}}}],"minimum_should_match":1,"filter":{"bool":{"should":[ {"term":{"id":"12"}}]}}}},"highlight":{"fields":{"text":{},"title":{}}}}
  • index are -> title, comment, text, doc, name 大约有 1000 条记录。我希望每个 id 中的 ('title','text','chapter') 中至少有一个“供应”匹配
  • 但它也给了我 id = "12" 记录,其中 "supply" 没有找到
猜你喜欢
  • 1970-01-01
  • 2022-10-26
  • 2019-09-25
  • 2016-10-05
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多