2016-05-26 15 views
0

アレイフィールドの集約合計の取得に問題があります。ElasticSearch集約アレイフィールドの合計

私は、casting.nameとcasting.categoryの2つのフィールドに基づいて集計を実行したいと思います。

My Schema: 
"mappings": { 
    "movies": { 
     "properties": { 
     "title" : { "type": "string" }, 
     "year" : { "type": "integer" }, 
     "casting": { 
      "type": "nested", 
      "properties": { 
      "name": { "type": "string" }, 
      "quantity": { "type": "long" } 
      } 
     } 
     } 
    } 
    } 

Iはcasting.quantityフィールドに基づいて別のTermsAggregation和であるsubaggregationと、casting.nameフィールドに基づいTermsAggregationと試みました。鋳造のすべての名前と数量フィールドを合計します

My Query representation is shown below: 

GET groups/_search?search_type=count 
{ 
    "query" : { 
     "terms" : { 
      "movies.casting.name" : ["gap"], 
      "minimum_should_match":1 
     } 
    }, 
    "aggregations" : { 
     "termsAggregation" : { 
      "terms" : { 
       "field" : "movies.casting.name" 
      },  
     "aggregations": { 
      "quantitySum": { 
       "filter" : { 
        "term" : { 
         "groups.permissions.product" : "ycsfa" }    
       }, 
       "aggregations" : { 
         "gapSum" : { 
          "sum" : { 
           "field" : "movies.casting.quantity" } 
         } 
        }    
      } 
     } 
     } 
    } 
} 

Showing wrong results ... 

結果...

任意のアイデアをここに?

答えて

0

あなたのフィールドがnestedあるので、あなたがnested QueryNested Aggregationを使用する必要があります。

GET groups/_search?search_type=count 
{ 
"query": { 
    "nested": { 
    "path": "casting", 
    "query": { 
     "terms": { 
      "movies.casting.name": [ 
       "gap" 
      ], 
      "minimum_should_match": 1 
     } 
    } 
    } 
} , 
"aggregations": { 
    "nested": { 
    "path": "casting" 
    }, 
    "aggs": { 
    "termsAggregation": { 
     "terms": { 
      "field": "movies.casting.name" 
     }, 
     "aggregations": { 
       "gapSum": { 
        "sum": { 
         "field": "movies.casting.quantity" 
        } 
       } 
       } 
     } 
     } 
    } 
} 
+0

は鋳造がネストされていないときになりますどのような...ありがとう??? –

+0

あなたが言ったクエリを使用することができます。 – Richa

+0

期待通りに機能しません...キャスト配列のすべての要素をクエリーします。 –

関連する問題