Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 按与文档相同的属性对Elasticsearch Bucket进行排序_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Aggregation - Fatal编程技术网 elasticsearch,aggregation,Sorting,elasticsearch,Aggregation" /> elasticsearch,aggregation,Sorting,elasticsearch,Aggregation" />

Sorting 按与文档相同的属性对Elasticsearch Bucket进行排序

Sorting 按与文档相同的属性对Elasticsearch Bucket进行排序,sorting,elasticsearch,aggregation,Sorting,elasticsearch,Aggregation,有一种方法可以按多个属性对文档进行排序。 我想按相同的属性以相同的方式对聚合的bucket进行排序。这可能吗 以下是我的示例文档: curl -XPOST 'localhost:9200/_bulk?pretty' -H 'Content-Type: application/json' -d' { "index" : { "_index" : "cars", "_type" : "cars", "_id" : "1" } } { "make":"BMW", "serie

有一种方法可以按多个属性对文档进行排序。 我想按相同的属性以相同的方式对聚合的bucket进行排序。这可能吗

以下是我的示例文档:

    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设置为true,以便能够聚合:

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" }
        }
      }
    }
  }
}
'

你知道如何按make和series对bucket进行排序吗?

首先,你可能想指定
make
series
为类型,而不是
text
,因为它不需要分析(你需要这些字段上的精确匹配)

您的输出是什么样子的?当我尝试它时,它似乎被正确地分类了

  [
    {
      "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
          }
        ]
      }
    }
  ]

我想在我的查询中添加一种
sort
参数,比如在对普通文档进行排序时:
“sort”:[{“series”:“desc”},{“make”:“asc”}]
,这样订单桶将首先按序列排序,然后按make排序