【问题标题】:FOSElasticaBundle sort not workingFOSElasticaBundle 排序不起作用
【发布时间】:2015-02-05 15:58:05
【问题描述】:

我的 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 排序,但也没有成功。

【问题讨论】:

    标签: symfony elasticsearch foselasticabundle


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 2013-04-07
      • 2015-05-19
      • 2012-09-20
      • 2015-06-23
      相关资源
      最近更新 更多