2017-04-20 96 views
0

我這上Elasticsearch 1.x工作正常,但由於bool filter2.x(我得到doc_count: 0)不起作用下面的查詢已被棄用。我不清楚如何使用新的Bool Query來重寫這個查詢。Elasticsearch聚集使用布爾過濾

{ 
    "aggregations": { 
    "events_per_period": { 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "terms": { 
       "message.facility": [ 
        "facility1", 
        "facility2", 
        "facility3" 
       ] 
       } 
      } 
      ] 
     } 
     } 
    } 
    }, 
    "size": 0 
} 

任何幫助,非常感謝。

+0

你以前的查詢是什麼? –

+0

@AndreiStefan - 我上面的查詢是我在1.x中返回'doc_count> 0'的一個,但是在2.x中返回0。 – jeffreyveon

+0

您還可以分享'message'字段和示例文檔的映射嗎? –

回答

0

我想你可能想要在多個字段上使用過濾器進行聚合: - 這裏我假定過濾器用於在facility1和facility2上進行id和聚合。

{ 
    "_source":false, 
    "query": { 
     "match": { 
      "id": "value" 
     } 
    }, 
    "aggregations": { 
     "byFacility1": { 
      "terms": { 
       "field": "facility1" 
      }, 
      "aggs": { 
       "byFacility2": { 
        "terms": { 
         "field": "facility2" 
        } 
       } 
      } 
     } 
    } 
} 

如果要在三個字段上進行聚合,請檢查link。 對於java的執行link2