i want to sort my result of companies based on the count of nested (employment)objects,
i added an extra field to the company entity that holds the count like:
private employeeCount;
getEmployeeCount(){
return count($this->employments);
}
and added it to the index like:
company:
mappings:
fullname: ~
employeeCount: ~
the field is correctly indexed and i get hits like:
"_hit": {
"_index": "search",
"_type": "company",
"_id": "2628",
"_source": {
"fullname": "acme",
"employeeCount": 9,
... },
"sort": [
"9"
]
i added the sort like:
$query->addSort(array('employeeCount' => array( 'order'=>'desc')));
and the result seems to be sorted correctly down from " 9, 8, 7, 6 ...",
but for some reason there are some results somewhere in the middle with higher employeeCount
for example this:
"_hit": {
"_index": "search",
"_type": "company",
"_id": "2668",
"_source": {
"fullname": "acme2",
"employeeCount": 18,
... },
"sort": [
"18"
]
i expect this result to be on top of my first example but it is somewhere between 2 and 1
so two guesses, it is sorting from 0-10 and everything greater than 10 is ignored
or there is some bug in elasticsearch or foselastica bundle,
heres the resulting query:
search/company/_search (GET) 5.59 ms {"sort":[{"employeeCount":{"order":"desc"}}],"query":{"wildcard":{"fullname":{"value":"**","boost":1}}},"size":"2000","from":0}
anybody any idea ?