温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - In which order elasticsearch filters applied?
elasticsearch

其他 - elasticsearch过滤器按什么顺序应用?

发布于 2020-04-08 12:37:07

目前,我在Rails应用程序中使用elasticsearch。我担心的是过滤器查询如何工作有没有优先级或排名,这个过滤器将首先和其他一个去年申请 从顶部适用于底部底部顶部: -

我有一个下面的过滤器的示例查询:

{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
            {
              "match_all": {

              }
            }
          ],
          "filter": [
            {
              "term": {
                "status": true
              }
            },
            {
              "geo_bounding_box": {
                "location": {
                  "top_left": {
                    "lat": 40.8888,
                    "lon": -73.888888
                  },
                  "bottom_right": {
                    "lat": 41.8888,
                    "lon": -74.88888
                  }
                }
              }
            },
            {
              "range": {
                "get_booking_cut_off_time": {
                  "gte": 5.46
                }
              }
            },
            {
              "terms": {
                "show_to_list_val": [
                  "Both",
                  "Direct"
                ]
              }
            },
            {
              "range": {
                "min_days": {
                  "lte": 1
                }
              }
            },
            {
              "terms": {
                "midoffice_master_id": [
                  10,
                  14
                ]
              }
            }
          ]
        }
      }
    }
  },
  "_source": {
    "includes": [
      "name",
      "code"
    ]
  },
  "size": 20,
  "from": 0
} 

所以在上面的例子中我有term filtergeo_bounding_box filterrange filter我想知道当查询命中elasticsearch api时应首先或最后应用哪个过滤器?

任何帮助将是可观的... :)

查看更多

提问者
code_aks
被浏览
108
apt-get_install_skill 2020-02-01 17:37

看看来自Elastic的这篇非常详细的博客文章,其中介绍了查询和过滤器执行的内部工作原理:

https://www.elastic.co/de/blog/elasticsearch-query-execution-order

在最后的结论部分中,他们声明(引用):

问:将查询/过滤器放入查询DSL的顺序是否重要?

答:不会,因为无论如何它们都会根据各自的成本和匹配成本自动重新排序。

希望这可以帮助!