0

我的 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: ~

我有扩展 FOS\ElasticaBundle\Repository 的 Repository 类,除了排序之外,一切都运行良好。

    $query = new \Elastica\Query();
    $query->setSort(array('created_at' => array('order' => 'desc')));        
    return $this->find($query);

得到一些不相关的结果,完全没有顺序。然后,我尝试在索引中添加模型 id 并尝试按 id 排序但也没有成功。

4

1 回答 1

2

解决方案是在 created_at 字段上设置 {type:date}。在那种情况下,ES 按时间戳排序,一切正常。

按 id 排序不起作用,因为以某种方式 categories.id 覆盖了主 id,然后我得到了按 category.id 而不是实体 id 排序的结果。

于 2015-02-06T11:34:41.917 回答