I want to perform a terms aggregation and in every results bucket get the hit fields after a script manipulation was performed.
For example, if these are the documents:
{"age": 15, "firstName": "Dana", "lastName": "Miller"}
{"age": 15, "firstName": "Michelle", "lastName": "Bob"}
{"age": 32, "firstName": "Mary", "lastName": "Smith"}
{"age": 32, "firstName": "Anna", "lastName": "Taylor"}
The aggregation is by the "age" field, and the script is: "return 'doc['firstName'] + ' ' + doc['lastName']"
The results should be:
bucket 1 (age: 15):
- "Dana Miller"
- "Michelle Bob"
Buchet 2 (age 32):
- Mary Smith
- Anna Taylor
Is this possible in elasticsearch?
EDIT:
In addition, I'm looking for a way to run a script over multiple hits in a bucket. For example, if we use the documents above and the terms aggregation by the age field, can I get the results of the hits in the bucket together in the following way?
Bucket 1 (age 15):
- "Dana Miller and Michelle Bob"
Bucket2 (age 32):
- "Mary Smith and Anna Taylor"
Is it possible in ES?
thank you.