I have a parent/child structure in 3 levels. Let's say:
Company -> Employee -> Availability
Since Availability (and also Employee) is frequently updated here, I choose using parent/child structure against nested. And search function works fine (all documents in correct shards).
Now I want to sort those results. Sorting them by meta data from company (1st level) is easy. But I need to sort also by 3rd level (availability).
I want list of companies which are sorted by:
- Distance from location given ASC
- Rating DESC
- Soonest availability ASC
For example:
Company A is 5 miles away, has rating 4 and soonest one of their employees is available in 20 hours Company B is also 5 miles away, also has rating 4 but soonest one of their employee is available in 5 hours.
Therefore sort result needs to be B, A.
I would like to append special weight to each of this data, so I started writing aggregations which I could later use in my custom_score script.
Full gist for creating index, importing data and searching
Now, I've managed to write a query which actually returns back result, but availability aggregation bucket is empty.
However, I'm also getting results back too structured, I would like to flatten them.
Currently I get back:
Company IDS -> Employee IDS -> first availability
I would like to have aggregation like:
Company IDS -> first availability
This way I'm able to do my custom_score
script to calculate score and sort them properly.
More simplified question:
How can one sort/aggregate by multi level (grand)children and possibly flatten the result.
Query Failed [Failed to execute main query]]; nested: NullPointerException;
. Can you execute your gist on your local environment and make sure it is ok? Thanks! – Val