elasticsearch 1.7 by bucket with multi field concat

时间:2017-03-20 23:46:22

标签: elasticsearch

我有一个汇总语句,按firstname分组,并将它们与必要字段一起存储。但是我希望通过firstname+lastname的连接进行分组。我不希望使用firstname之类的嵌套聚合,然后按lastname分组。如何更改字段以包含多个字段的字符串连接?

"aggs": {
    "by_name": {
      "terms": {
        "field": "firstname"
      },
      "aggs": {
        "source": {
          "top_hits": {
            "_source": {
              "include": [
                "id","name"
              ]
            }
          }
        }
      }
    }
  }

1 个答案:

答案 0 :(得分:1)

在ES 1.7中

您可以使用script aggregation with terms aggregation

GET _search
{
  "size": 20,
  "aggs": {
    "con": {
      "terms": {
        "script": "doc['firstName'].value + doc['lastName'].value"
      }
    }
  }
}

对于当前版本,即。 ES 5.2,出于同一目的有bucket script aggregaton