ManFung Chan
ManFung Chan

Reputation: 1

how to get an elasticsearch aggregation by multiple fields concat

i want to get an ES aggregation by two or more fields, but not to aggregate one by one, but to concat() these fields as a new one, and aggregate by these new one filed, so how to do it ? thanks

Upvotes: 0

Views: 2654

Answers (1)

vvucetic
vvucetic

Reputation: 499

Although it's an old post, might be useful to someone. Something like this could work:

GET index/_search
{
  "size": 0,
  "query":{ 
    "match_all": {}
  },
  "aggs": {
    "unique_count": {
      "cardinality": {
        "script": {
          "lang": "painless",
          "source": "doc['field1'].value + '#' + doc['field2'].value"
        }
      }
    }
  }
}

Upvotes: 5

Related Questions