Hi everyone,
I am working on data modeling restaurants. A restaurants can have employees (which is a nested array of Employee) and an employee has a profession.
The idea behind the following query attempt is to return all restaurants which employ people in more than 3 distinct professions, sorted by the amount of distinct professions. Except for the sorting, the query runs perfectly fine, but I have trouble getting the sorting right.
Do you guys have any ideas?
{
"size": 0,
"sort": [],
"query": {
"match_all": {}
},
"aggs": {
"auxilary_id_grouping": {
"terms": {
"field": "_uid",
"order": {
"nested_employees_position_cardinality>employees_position_cardinality": "asc"
}
},
"aggs": {
"nested_employees_position_cardinality": {
"nested": {
"path": "employees"
},
"aggs": {
"employees_position_cardinality": {
"cardinality": {
"field": "employees.position"
}
}
}
},
"main_selector_agg": {
"bucket_selector": {
"script": {
"inline": "(params.employees_position_cardinality) > (3)"
},
"buckets_path": {
"employees_position_cardinality": "nested_employees_position_cardinality>employees_position_cardinality"
}
}
},
"auxilary_actual_document": {
"top_hits": {
"size": 1
}
}
}
}
}
}