Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony Elasticsearch-foselastica按整数排序,结果奇怪_Symfony_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Elastica_Foselasticabundle - Fatal编程技术网 elasticsearch,elastica,foselasticabundle,Symfony,Sorting,elasticsearch,Elastica,Foselasticabundle" /> elasticsearch,elastica,foselasticabundle,Symfony,Sorting,elasticsearch,Elastica,Foselasticabundle" />

Symfony Elasticsearch-foselastica按整数排序,结果奇怪

Symfony Elasticsearch-foselastica按整数排序,结果奇怪,symfony,sorting,elasticsearch,elastica,foselasticabundle,Symfony,Sorting,elasticsearch,Elastica,Foselasticabundle,我想根据嵌套employmentobjects的计数对公司结果进行排序 我在公司实体中添加了一个额外字段,该字段保存计数,如下所示: private employeeCount; getEmployeeCount(){ return count($this->employments); } 并将其添加到索引中,如: company: mappings: fullname: ~

我想根据嵌套employmentobjects的计数对公司结果进行排序

我在公司实体中添加了一个额外字段,该字段保存计数,如下所示:

private employeeCount;

getEmployeeCount(){
  return count($this->employments);
}
并将其添加到索引中,如:

            company:
                mappings:
                    fullname: ~ 
                    employeeCount: ~ 
该字段已正确索引,我得到的命中率如下:

"_hit": {
"_index": "search",
"_type": "company",
"_id": "2628",
"_source": {
"fullname": "acme",
"employeeCount": 9,
... },
"sort": [
"9"
]
我添加了这样的内容:

$query->addSort(array('employeeCount' => array( 'order'=>'desc')));
结果似乎从9,8,7,6中正确排序

但是,由于某种原因,在某个中间出现了一些结果,而员工人数的增加更是如此。 例如:

"_hit": {
"_index": "search",
"_type": "company",
"_id": "2668",
"_source": {
"fullname": "acme2",
"employeeCount": 18,
... },
"sort": [
"18"
]
我希望这个结果在我的第一个例子的基础上,但它在2到1之间

所以两次猜测,它是从0到10排序的,大于10的都被忽略

或者在elasticsearch或foselastica束中有一些缺陷

结果查询如下:

search/company/_search (GET) 5.59 ms {"sort":[{"employeeCount":{"order":"desc"}}],"query":{"wildcard":{"fullname":{"value":"**","boost":1}}},"size":"2000","from":0}

有人知道吗

似乎是作为字符串而不是整数排序。您可以向排序参数添加一个类型来指定整数。

我也有同样的问题,您找到答案了吗?不幸的是,我没有找到任何解决方案。请随意请求开发者,我没有。我在这里找到了答案:很好!多谢各位