使用 default_operator 作为 AND 的查询字符串在 ES 2.4 和 ES 6.8 中的工作方式不同

Query string with default_operator as AND works differently in ES 2.4 and ES 6.8

query_string 似乎是 returning 匹配 ES 2.4 中的字段参数中指定的所有字段的文档,而在 ES 6.8 中匹配每个字段的所有术语的文档是returned.

重现步骤: 将以下文档插入到 ES 2.4 和 ES 6.8 集群中:

PUT yields_test/il4/1
{
    "security_name":"high term1",
    "doc_type":"YIELDS"
}

PUT yields_test/il4/2
{
    "security_name":"high term2",
    "doc_type":"YIELDS"
}

PUT yields_test/il4/3
{
    "security_name":"low term2",
    "doc_type":"YIELDS"
}

PUT yields_test/il4/4
{
    "security_name":"low term1",
    "doc_type":"YIELDS"
}

PUT yields_test/il4/5
{
    "security_name":"high yield",
    "doc_type":"YIELDS"
}

PUT yields_test/il4/6
{
    "security_name":"high yields",
    "doc_type":"YIELDS"
}

PUT yields_test/il4/7
{
    "security_name":"high term3",
    "doc_type":"YIELD"
}

并尝试在它们中使用以下 query_string 查询进行搜索:

GET yields_test/_search
{
    "query": {
        "query_string": {
           "fields": [
              "security_name",
                  "doc_type"
           ], 
           "query": "high yield",
           "default_operator": "AND"
        }
    }
}

ES 2.4 returns 以下文件:

[
         {
            "_index": "yields_test",
            "_type": "il4",
            "_id": "7",
            "_score": 0.5098911,
            "_source": {
               "security_name": "high term3",
               "doc_type": "YIELD"
            }
         },
         {
            "_index": "yields_test",
            "_type": "il4",
            "_id": "5",
            "_score": 0.08322528,
            "_source": {
               "security_name": "high yield",
               "doc_type": "YIELDS"
            }
         }
      ]

而 ES 6.8 return 如下:

[
         {
            "_index": "yields_test",
            "_type": "il4",
            "_id": "5",
            "_score": 0.5753642,
            "_source": {
               "security_name": "high yield",
               "doc_type": "YIELDS"
            }
         }
]

我能够通过使用请求正文中的配置文件字段找到版本之间的变化。 两者创建的 Lucene 查询不同。

ES 2.4 生成的 Lucene 查询: +(security_name:high | doc_type:high) +(security_name:yield | doc_type:yield)

通过 ES 6.8: ((+security_name:high +security_name:yield) | (+doc_type:high +doc_type:yield))

关于如何在 ES 6.8 中 return 相同文档的另一个问题仍然存在。

您可以使用布尔查询:

{
  "query" : {
    "bool" : { 
      "must" : [
        {"query_string": {
             "fields": [ "security_name","doc_type" ], 
             "query": "high",           
            }},
        { "query_string": {
             "fields": [ "security_name","doc_type" ], 
             "query": "yeild", }}
      ]
    }
  }
}