2014-08-28 59 views
0

我有一個包含產品的elasticsearch索引,我可以查詢不同的搜索詞。每個產品都包含一個字段shop_id以引用它所屬的商店。現在我嘗試顯示所有商店的列表,供我查詢。 (按商店過濾) 據我在類似的問題上閱讀,我不得不使用聚合。最後,我建立了這個查詢:Elasticsearch:查詢的綜合結果

curl -XGET 'http://localhost:9200/searchindex/_search?search_type=count&pretty=true' -d '{ 
    "query" : { 
     "match" : { 
      "_all" : "playstation" 
     } 
    }, 
    "aggregations": { 
    "shops_count": { 
     "terms": { 
     "field": "shop_id" 
     } 
    } 
    } 
}' 

這應搜索playstation和彙總基於shop_id結果。可悲的是,它只返回

數據太大,數據將大於限制[8534150348] 字節]。

我也試着用查詢返回2個結果。 該指數包含超過90,000,000種產品。

回答

1

我會建議這是一個過濾器聚合的工作。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html

注:我不知道你的索引你的產品的映射,所以如果過濾器下無法正常工作,從http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filters.html

{ 
    "aggs" : { 
     "in_stock_playstation" : { 
      "filter" : { "term" : { "change_me_to_field_for_product" : "playstation" } } }, 
      "aggs" : { 
       "shop_count" : { "terms" : { "field" : "shop_id" } } 
      } 
     } 
    } 
} 
+1

感謝您的建議,嘗試另一種過濾器。這也會導致內存錯誤。我懷疑elasticsearch試圖在應用過濾器之前執行聚合。即使只返回2個結果的查詢也會失敗。 – 2014-08-29 07:36:32

+0

實際上,過濾器聚合過濾器,然後聚合(注意「aggs」的嵌套)。也許這可能會有所幫助:https://stackoverflow.com/questions/25367420/elasticsearch-why-is-it-recommended-to-use-50-of-available-memory-for-the-hea – cheekybastard 2014-08-29 08:53:06