Hi there!
I'm dealing with the following situation.
I have some data ingested into elasticsearch which present a field "certainField" which can either be null or contain an unspecified number of JSON objects.
My goal is to make an average of all the occurrences of a nested field present in any of those JSON object and write this average as the value of a first level field of the document.
To make an example I have something like:
@timestamp: ...
name: ...
certainField: [
{
nestedField1: ...
nestedField2: ...
interestingNestedField: 35
...
},
{
nestedField1: ...
nestedField2: ...
interestingNestedField: 42
...
},
{
nestedField1: ...
nestedField2: ...
interestingNestedField: 12
...
}
]
I would like to use an ingest pipeline so as to have another first level field interestingFieldAverage: 29,66 like the following:
@timestamp: ...
name: ...
interestingFieldAverage: 29,66
certainField: [
{
nestedField1: ...
nestedField2: ...
interestingNestedField: 35
...
},
{
nestedField1: ...
nestedField2: ...
interestingNestedField: 42
...
},
{
nestedField1: ...
nestedField2: ...
interestingNestedField: 12
...
}
]
Is there any way to accomplish such a task? Obsiously I'd need a way to iterate over the nested JSON objects without knowing in advance their number (as said it varies from document to document).
Thank you!