按日期排序的elasticsearch不起作用

时间:2015-02-16 15:10:07

标签: elasticsearch

我遇到了在elasticsearch上按日期排序的问题。根据elasticsearch http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_sorting.html

提供的文档

我使用以下代码按日期排序

{"sort":{"posted_on":{"order":"desc"}}}

以下是结果

{
"took": 3,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
},
"hits": {
    "total": 305,
    "max_score": null,
    "hits": [
        {
            "_index": "ads",
            "_type": "ad",
            "_id": "52d6945f1d41c812bf000004",
            "_score": null,
            "_source": {
                "category": "Cars and Bikes",
                "description": "Innova 2010(V) DC",
                "posted_on": "2014-09-04T18:11:57+00:00",
                "slug_id": "innova-2010-v-dc",
                "title": "Innova 2010(V) DC"
            },
            "sort": [
                "57"
            ]
        }
        ,
        {
            "_index": "ads",
            "_type": "ad",
            "_id": "5408accf1d41c8b8f1000001",
            "_score": null,
            "_source": {
                "category": "",
                "description": "rrrrrrrrrrfsadsadfsadfsa",
                "posted_on": "2014-09-04T18:11:57+00:00",
                "slug_id": "test",
                "title": "test"
            },
            "sort": [
                "57"
            ]
        }
        ,
        {
            "_index": "ads",
            "_type": "ad",
            "_id": "52d6945f1d41c812bf000003",
            "_score": null,
            "_source": {
                "category": "Cars and Bikes",
                "description": "Indica DLS 2006 for immediate sale",
                "posted_on": "2015-02-16T12:46:10+00:00",
                "slug_id": "indica-dls",
                "title": "Indica DLS"
            },
            "sort": [
                "46"
            ]
        }
        ,
        {
            "_index": "ads",
            "_type": "ad",
            "_id": "52d694981d41c812d800000a",
            "_score": null,
            "_source": {
                "category": "Automotive",
                "description": "MAHINDRA XYLO 2011 MAY Hyderabad registration for immediate sale cash party ",
                "posted_on": "2015-02-16T12:46:10+00:00",
                "slug_id": "mahindra-xylo-2011-may-hyderabad-registration",
                "title": "MAHINDRA XYLO 2011 MAY Hyderabad registration"
            },
            "sort": [
                "46"
            ]
        }
        ,
        {
            "_index": "ads",
            "_type": "ad",
            "_id": "52d694981d41c812d8000010",
            "_score": null,
            "_source": {
                "category": "Automotive",
                "description": "SWIFT LDI 2008 Black,single owner, Hyderabad Registration, Excellent Condition",
                "posted_on": "2015-02-16T12:46:10+00:00",
                "slug_id": "swift-ldi-2008-black",
                "title": "SWIFT LDI 2008 Black"
            },
            "sort": [
                "46"
            ]
        }

查询中有什么问题吗? 谢谢, Aashish

1 个答案:

答案 0 :(得分:1)

回答这个问题,就像aashish说的那样。发生这种情况时,您可能需要查看您的地图字段,并确保该字段的类型"日期"。

您可能还想按照here

中的说明指定日期格式