[英]elasticsearch date-range query 0 hits
I'm trying to query my docs with a date-range query. 我正在尝试使用日期范围查询来查询我的文档。
Doing a get for one of my docs gives me something like that: 为我的其中一个文档获取内容会给我这样的东西:
{
"_index": "offer",
"_type": "offer",
"_id": "offer3",
"_score": 1,
"_source": {
"offer": {
"properties": {
"starts_at": "12/10/2015T14:27:49.197962+00:00",
"ends_at": "14/11/2016T07:59:49.197962+00:00",
"duration": "1.0"
}
}
}
}
I have a query in this form, where I have the exact value of ends_at copied into my query, but I still get 0 hits. 我有这种形式的查询,在其中我将ends_at的确切值复制到了查询中,但我仍然得到0次点击。 Where am I going wrong? 我要去哪里错了?
curl -XGET "http://localhost:9200/offer/offer/_search" -d'
{
"query": {
"range": {
"ends_at": {
"lte": "14/11/2016T07:59:49.197962+00:00"
}
}
}
}
Since your date format is dateOptionalTime
your documents need to have the correct ISO8601 date format , ie either yyyy-MM-dd
(without time) or yyyy-MM-ddTHH:mm:ss.SSSZ
(with time) 由于您的日期格式为dateOptionalTime
您的文件需要有正确的ISO8601日期格式 ,即无论是yyyy-MM-dd
(无时间)或yyyy-MM-ddTHH:mm:ss.SSSZ
(随时间)
In your case that would mean that your dates need to be formatted like this instead: 在您的情况下,这意味着您的日期需要这样格式化:
2016-11-14T07:59:49.197+00:00
You need to wipe your index, fix your mapping and re-index your data properly. 您需要擦除索引,修复映射并正确重新索引数据。
Then you'll be able to search using this query: 然后,您将可以使用以下查询进行搜索:
curl -XGET "http://localhost:9200/offer/offer/_search" -d'
{
"query": {
"range": {
"properties.ends_at": {
"lte":"2016-11-14T07:59:49.197+00:00"
}
}
}
}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.