Aggregating query results nested documents by nested field
This post has NOT been accepted by the mailing list yet.
I've been looking for a while for answer, couldn't find a similar use case in the internet. I have an index of customers with nested documents of addresses. Each Customer could have zero to many addresses. The addresses could contain duplicates which could be identified by a specific field - mergeID. This is not possible to know while inserting the data because the data is updated in different points in time. I wish to aggregate the nested documents when returning the results.
For example: a search query on David Anderson returns the following document:
The documents contains 3 nested documents with 3 addresses, 2 of the 3 addresses are basically the same. I wish to aggregate the nested documents by the "mergeID" field, and perhaps display only the first address document for each mergeID. Any idea how this could be achieved in query? In this case the result should be the parent document with 2 nested addresses one for Paris and one for Basel. It is also important to mention that not all addresses might have a mergeID field, in this case we would want to display them too.