【发布时间】:2017-05-19 05:17:27
【问题描述】:
我在 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"
]
}
他们的查询有什么问题吗? 谢谢, 阿什什
【问题讨论】:
-
同样的问题。您找到任何解决方案了吗?谢谢!
-
是的,我找到了解决方案。我将posted_on 列索引为字符串。所以,这就是问题所在。将posted_on 列索引为日期对我有用。
-
我这边几乎一样。我使用了“日期”类型,但格式错误。 ElasticSearch 静默排序错误,不会引发任何问题。
-
我有同样的问题,但我已经设置为日期并指定格式,但仍然无法正常工作。
标签: elasticsearch