简体   繁体   English

弹性搜索按列排序

[英]elastic search sort in aggs by column

I am trying to sort in elastic search in aggs, equivalent in mysql "ORDER BY Title ASC/DESC". 我正在尝试在aggs中进行弹性搜索,相当于mysql“ ORDER BY Title ASC / DESC”。 Here is the index structure: 这是索引结构:

'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'
                        )
    )
  )
)

I can order by Price as follows: 我可以按以下价格订购:

{
      "aggs": {
        "group_by_product": {
          "terms": {
            "field": "ProductId",
              "order": {
                "product_price" : "asc"
            }
          },
          "aggs": {
            "product_price": {
              "avg": {
                "field": "Price"
              }
            }
          }
        }
      }
    }

But it is not possible to order by Title (ORDER BY Title ASC/DESC). 但是无法按标题(ORDER BY标题ASC / DESC)订购。

Is there any way to sort by Title? 有什么办法按标题排序吗?

Thank you very much in advance! 提前非常感谢您!

Regards 问候

Edit to reflect clarification in comments: 编辑以在评论中反映澄清:

To sort an aggregation by string value use an intrinsic sort , however sorting on non numeric metric aggregations is not currently supported. 要使用字符串值对聚合进行排序 ,请使用内部排序 ,但是当前不支持对非数字度量聚合进行排序。

"aggs" : {
        "order_by_title" : {
            "terms" : {
              "field" : "title",
              "order": {
                "_term" : "asc" 
              }
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM