2016-04-24 19 views
1

私はElastic Searchを使い始めていますが、何らかの集約をしようとしています。基本的に、私は、次の形式のデータからなるデータセットがあります。今弾性検索条件でバケツに集計する

{ 
    "name": "The Chef Restaurant", 
    "city": "New York", 
    "state": "New York", 
    "rating": "GOOD", 
    "type": "Continental" 
} 

を、私はいくつかの集約を行うと、1つのクエリですべてのコンチネンタルレストラン、良いレストラン、ニューヨークのレストランを取得したいです。

私はすべてのタイプのレストランの数を望んでいないことに注意してください、私はちょうど特定のタイプのカウントが欲しいです。また、これらの集約は相互に独立しています。つまり、私がGOODと言うと、必ずしもコンチネンタルであるとは限りません。イタリア語なのかもしれません。

これは私がしようとしたものです:

{ 
    "size": 0, 
    "query": { 
     "match_all": {} 
    }, 
    "aggregations": { 
     "good_restaurants": { 
      "filters": { 
       "match": { 
        "rating": "CONTINENTAL" 
       } 
      } 
     }, 
     "continental_restaurants": { 
      "filters": { 
       "match": { 
        "type": "CONTINENTAL" 
       } 
      } 
     }, 
     "restaurants_in_new_york": { 
      "filters": { 
       "match": { 
        "type": "CONTINENTAL" 
       } 
      } 
     } 
    } 
} 

私にエラーを与える:

{ 
    "error": { 
     "root_cause": [ 
     { 
      "type": "search_parse_exception", 
      "reason": "Unknown key for a START_OBJECT in [good_restaurants]: [match].", 
      "line": 9, 
      "col": 17 
     } 
     ], 
     "type": "search_phase_execution_exception", 
     "reason": "all shards failed", 
     "phase": "query", 
     "grouped": true, 
     "failed_shards": [ 
     { 
      "shard": 0, 
      "index": "test_master", 
      "node": "-aWy78_mRaaBMcOAeiN9tg", 
      "reason": { 
       "type": "search_parse_exception", 
       "reason": "Unknown key for a START_OBJECT in [good_restaurants]: [match].", 
       "line": 9, 
       "col": 17 
      } 
     } 
     ] 
    }, 
    "status": 400 
} 

私は、これは単純な質問のように思えるけど、私は長い間それで立ち往生されています時間。どんな助けもありがとう。

答えて

1

あなたはそれがこのようにそれをすることによって、あなたが期待するように動作させることができます。

{ 
    "size": 0, 
    "query": { 
    "match_all": {} 
    }, 
    "aggregations": { 
    "selected_types": { 
     "filters": { 
     "filters": { 
      "good_restaurants": { 
      "match": { 
       "rating": "CONTINENTAL" 
      } 
      }, 
      "continental_restaurants": { 
      "match": { 
       "type": "CONTINENTAL" 
      } 
      }, 
      "restaurants_in_new_york": { 
      "match": { 
       "type": "CONTINENTAL" 
      } 
      } 
     } 
     } 
    } 
    } 
} 
関連する問題