我的elastica类型的配置如下所示:
acme_article:
mappings:
title: {type:string, index_analyzer:acme_analyzer}
content: {type:string, index_analyzer:acme_analyzer}
slug: ~
media: {type:string, index_analyzer:acme_analyzer}
categories:
type: "object"
properties:
name: ~
id: ~
instance:
type: "object"
properties:
name: ~
created_by: ~
created_at: ~我有Repository类,它扩展了FOS\ElasticaBundle\Repository,除了排序之外,一切都运行得很好。
$query = new \Elastica\Query();
$query->setSort(array('created_at' => array('order' => 'desc')));
return $this->find($query);得到一些不相关的结果,完全没有顺序。然后,我尝试在索引中添加model id,并尝试按id排序,但也没有成功。
发布于 2015-02-06 19:34:42
解决方法是在created_at字段上设置{type:date}。在这种情况下,按时间戳排序,一切都是正常的。
按id排序不起作用,因为在某种程度上,categories.id覆盖了主id,然后我得到了按category.id而不是实体id排序的结果。
https://stackoverflow.com/questions/28348459
复制相似问题