0
可以通過多個屬性對文檔進行排序。 我想通過相同的屬性以相同的方式對聚合桶進行排序。這可能嗎?對與文檔具有相同屬性的Elasticsearch存儲桶進行排序
這裏是我的示例文件:
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}
'
這裏我設置fielddata到真正能夠聚合:
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
}
}
}
'
這裏是查詢聚合桶:
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" }
}
}
}
}
}
'
任何想法如何按品牌和系列來分類桶?
我要添加到我的查詢類型的'sort'參數,當我整理正常文檔,如:'「排序」:[{ 「系列」:「遞減」},{ 「做」 :「asc」} ]',這樣訂單存儲桶將按照系列先排序, –