2017-06-16 4 views
0

複数の属性で文書をソートする方法があります。 同じ属性で同じ方法で集約バケットをソートする必要があります。これは可能ですか?ここで文書と同じ属性のElasticsearchバケットを並べ替えます。

は私のサンプル文書です:

curl -XGET 'localhost:9200/cars/cars/_search?pretty' -d' 
{ 
    "size": 0, 
    "aggregations" : { 
    "CARS" : { 
     "terms" : { 
     "script" : { 
      "inline" : "doc[\"make\"].value + \"_\" + doc[\"series\"].value", 
      "lang" : "painless" 
     }  
     }, 
     "aggregations" : { 
     "make" : { 
      "terms" : { "field" : "make"} 
     }, 
     "series" : { 
      "terms" : { "field" : "series" } 
     } 
     } 
    } 
    } 
} 
' 
:ここ
curl -XPUT 'localhost:9200/cars/_mapping/cars?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "properties": { 
    "make": { 
     "type":  "text", 
     "fielddata": true 
    }, 
    "series": { 
     "type":  "text", 
     "fielddata": true 
    } 
    } 
} 
' 

が集計バケットクエリです:ここで私が凝集することができるようにするにはtrueにfielddataを設定してい

curl -XPOST 'localhost:9200/_bulk?pretty' -H 'Content-Type: 
application/json' -d' 
    { "index" : { "_index" : "cars", "_type" : "cars", "_id" : "1" } } 
    { "make":"BMW", "series":"3er", "doorCount": 4} 
    { "index" : { "_index" : "cars", "_type" : "cars", "_id" : "2" } } 
    { "make":"BMW", "series":"3er", "doorCount": 5} 
    { "index" : { "_index" : "cars", "_type" : "cars", "_id" : "3" } } 
    { "make":"Opel", "series":"Astra", "doorCount": 2} 
    { "index" : { "_index" : "cars", "_type" : "cars", "_id" : "4" } } 
    { "make":"Opel", "series":"Omega", "doorCount": 2} 
    ' 

makeとseriesでバケツを並べ替える方法はありますか?

答えて

0

まず第一に、あなたはおそらく(あなたがこれらのフィールドの完全な一致をしたい)、それを分析する必要がないため、タイプkeywordの代わりtextであることがmakeseriesを指定します。

出力はどのように見えますか?私はそれを試したとき、それは正しくソートされているようだ。 `「ソート」:[ {「シリーズ」:「DESC」}

私は、通常の文書をソートしていたときのような` sort`パラメータの私のクエリの種類に追加する
[ 
    { 
     "key": "bmw_3er", 
     "doc_count": 2, 
     "series": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "3er", 
      "doc_count": 2 
      } 
     ] 
     }, 
     "make": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "bmw", 
      "doc_count": 2 
      } 
     ] 
     } 
    }, 
    { 
     "key": "opel_astra", 
     "doc_count": 1, 
     "series": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "astra", 
      "doc_count": 1 
      } 
     ] 
     }, 
     "make": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "opel", 
      "doc_count": 1 
      } 
     ] 
     } 
    }, 
    { 
     "key": "opel_omega", 
     "doc_count": 1, 
     "series": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "omega", 
      "doc_count": 1 
      } 
     ] 
     }, 
     "make": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "opel", 
      "doc_count": 1 
      } 
     ] 
     } 
    } 
    ] 
+0

、 {「作ります」 : "asc"} ] 'と書かれているので、注文バケットは最初にシリーズでソートされ、makeは2番目にソートされます –

関連する問題