【问题标题】:Does terms-lookup-filter aggregation order in elasticsearch query affect the execution time (efficiency)?elasticsearch查询中的terms-lookup-filter聚合顺序是否会影响执行时间(效率)?
【发布时间】:2017-06-06 04:15:42
【问题描述】:

我有以下带有术语查找过滤器聚合的弹性搜索查询。两个查询都会给出相同的结果。两个查询具有相同的过滤器类型,只是terms-lookup-filter 的顺序(位置)不同。

1.这里的术语查找过滤器位于 过滤器聚合的第二个/最后一个位置。

  {
   "size": 0,
   "aggs": {
      "filterAggs": {
         "filter": {
            "and": {
               "filters": [
                  {
                     "range": {
                        "eligibleDates": {
                           "include_lower": true,
                           "include_upper": true,
                           "from": <fromDate>,
                           "to": <toDate>
                        }
                     }
                  },
                  {
                     "terms": {
                        "rollNo": {
                           "path": "student.rollNo",
                           "index": "<index_name>",
                           "id": "<record_id>",
                           "type": "<es Type>"
                        }
                     }
                  }
               ]
            }
         }
      }
   }
}

2.这里的terms-lookup过滤器在过滤器聚合的第一个位置。

{
   "size": 0,
   "aggs": {
      "filterAggs": {
         "filter": {
            "and": {
               "filters": [
                  {
                     "terms": {
                        "rollNo": {
                           "path": "student.rollNo",
                           "index": "<index_name>",
                           "id": "<record_id>",
                           "type": "<es Type>"
                        }
                     }
                  },
                  {
                     "range": {
                        "eligibleDates": {
                           "include_lower": true,
                           "include_upper": true,
                           "from": <fromDate>,
                           "to": <toDate>
                        }
                     }
                  }
               ]
            }
         }
      }
   }
}

在我的实验/测试中,第一个查询比第二个查询执行效率更高(快 7 到 10 倍)。 现在我的问题是,弹性搜索查询中的术语查找过滤器聚合顺序会影响执行时间(效率)吗?过滤器放置顺序将如何影响执行时间?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    没关系,因为elasticsearch会通过特定算法找到优化的执行顺序
    我在一些文章中看到他们说您应该按某些标准对过滤器/查询进行排序(例如,应该首先过滤哪个过滤器)但是在阅读了一篇非常详细和准确的文章后发现它们不正确强>。 这是一篇关于 elasticsearch 中过滤器/查询执行顺序的好文章:

    In which order are my Elasticsearch queries/filters executed?

    如果您想优化您的查询,我建议您阅读以下内容:

    Optimizing Elasticsearch Searches

    例如,您有range filter,可以使用Cache Granularity and Acceleration Filters 部分对其进行优化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 2016-09-17
      • 1970-01-01
      相关资源
      最近更新 更多