流在 elasticsearch 查询中是如何工作的?

How does the flow works in elasticsearch queries?

我写了一个查询,它有几个条件,如下所示。

     GET /agreement/_search
        {
          "query": {
            "bool": {
              "must": [
                {
                  "multi_match": {
                    "query": "T-0668",
                    "fields": [
                      "agreecondition.agreementId",
                      "agreecondition.conditionContractId"
                    ]
                  }
                },
    ,
            {
              "range": {
                "agreecondition.validFrom": {
                  "gte": "02/18/2019"
                }
              }
            },
            {
              "range": {
                "agreecondition.validTo": {
                  "lte": "03/07/2019"
                }
              }
            }
              ],
              "filter": [
                {
                  "terms": {
                    "agreecondition.promotionId.keyword": [
                    "x",
"y"
                    ]
                  }
                }
              ]
            }
          }
        }

我的问题是流程是如何运作的?

Ex: ES 是否先获取 must 条件的多匹配的结果,并且在多匹配的输出上,范围条件是否适用?然后是过滤器(在范围条件的输出之上)?

我只是想弄清楚这一点,如果我的假设是错误的,那么我需要重新编写查询。

您可以检查 elasticsearch official blog on query execution order 以详细了解这一点,但由于博客末尾提到的 elastic put 限制,您可能无法获得所需的所有详细信息:

Q: How can I check which query/filter got executed first?

A:我们并没有真正公开这些信息,这是非常内部的。但是如果你

check the output of the profile API, you can count how many times nextDoc/advance have been called on the one hand, and matches on the other hand. Query nodes that have the higher counts have been run first.

注意:Profile API 也会像博客中建议的那样对您有用。