[英]Range query with elasticsearch for date saved as type “text”
I want to search for documents falls on a given date range but the range query doesn't return any result. 我想在给定的日期范围内搜索文档,但范围查询不会返回任何结果。
Field mapping: TestDate 字段映射:TestDate
type "text" fields 键入“文本”字段
keyword type "keyword" ignore_above 256 关键字类型“关键字”ignore_above 256
I have tried this "range": {"TestDate": {"gte": "2015-01-01","lte":"2015-02-01"}} 我试过这个“范围”:{“TestDate”:{“gte”:“2015-01-01”,“lte”:“2015-02-01”}}
I want all the documents satisfying the above condition. 我希望所有文件都满足上述条件。
You need to map the field as a date
instead, otherwise it won't work being mapped as text
您需要将该字段映射为date
,否则将无法映射为text
{
...
"TestDate": {
"type": "date"
}
...
}
Only then your range
query will work: 只有这样你的range
查询才会起作用:
{
"query": {
"range": {
"TestDate": {
"gte": "2015-01-01",
"lte":"2015-02-01"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.