按列在aggs中进行弹性搜索排序

Sen*_*ini 2 sorting group-by elasticsearch

我正在尝试在 aggs 中对弹性搜索进行排序,相当于在 mysql“ORDER BY Title ASC/DESC”中。这是索引结构:

'body' => array(
  'mappings' => array(
    'test_type' => array(
      '_source' => array(
        'enabled' => true
    ),
    'properties' => array(
      'ProductId' => array(
        'type'      => 'integer',
         'index'     => 'not_analyzed'
      ),
      'Title' => array(
        'type'      => 'string',
        'index'     => 'not_analyzed'
      ),
      'Price' => array(
        'type'      => 'double',
         'index'     => 'not_analyzed'
                        )
    )
  )
)
Run Code Online (Sandbox Code Playgroud)

我可以按价格订购如下:

{
      "aggs": {
        "group_by_product": {
          "terms": {
            "field": "ProductId",
              "order": {
                "product_price" : "asc"
            }
          },
          "aggs": {
            "product_price": {
              "avg": {
                "field": "Price"
              }
            }
          }
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

但是不能按标题排序(ORDER BY Title ASC/DESC)。

有没有办法按标题排序?

非常感谢您提前!

问候

Dan*_*ing 7

编辑以反映评论中的澄清:

要按字符串值对聚合进行排序,请使用内部 sort,但是当前不支持对非数字度量聚合进行排序。

"aggs" : {
        "order_by_title" : {
            "terms" : {
              "field" : "title",
              "order": {
                "_term" : "asc" 
              }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)