Reputation: 4687
I have an aggregate statement that groups by firstname
and buckets them with necessary fields. But I want to group by concatenation of firstname+lastname
. I do not want to use nested aggregates like group by firstname
and then group by lastname
. How do I change the field to include a string concatenation of multiple fields?
"aggs": {
"by_name": {
"terms": {
"field": "firstname"
},
"aggs": {
"source": {
"top_hits": {
"_source": {
"include": [
"id","name"
]
}
}
}
}
}
}
Upvotes: 0
Views: 817
Reputation: 16355
In ES 1.7
You may use script aggregation with terms aggregation
GET _search
{
"size": 20,
"aggs": {
"con": {
"terms": {
"script": "doc['firstName'].value + doc['lastName'].value"
}
}
}
}
For current version, ie. ES 5.2, there is bucket script aggregaton for the same purpose
Upvotes: 1