2017-06-06 339 views
3

我有以下elasticsearch查詢與術語查找過濾器聚合。兩個查詢都會得到相同的結果。兩個查詢都具有相同的過濾器類型,只不同的是術語 - 查找過濾器的順序(位置)。elasticsearch查詢中的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.Here術語的查找過濾器是在濾波器聚集第一位置。

{ 
    "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查詢中的terms-lookup-filter聚合順序是否會影響執行時間(效率)?過濾器放置順序將如何影響執行時間?

回答

0

沒有不要緊,因爲elasticsearch將通過特定的算法找到優化的執行順序
我在一些文章中看到他們說你應該通過一些標準命令來過濾器/查詢(例如哪一個更應該先放置過濾器),但是在閱讀非常詳細和準確的文章後發現它們是不正確。 這是關於過濾器/查詢執行順序elasticsearch偉大的文章:

In which order are my Elasticsearch queries/filters executed?

如果你想優化你的查詢,我會建議你閱讀本:

Optimizing Elasticsearch Searches

例如,您有range filter,可以使用Cache Granularity and Acceleration Filters部件進行優化。

相關問題