[英]elasticsearch- how to find exact date type values?
So I'm using elasticsearch with spring framework, and I'm having trouble get hits by exact date value. 所以我正在使用带弹簧框架的弹性搜索,而我很难通过确切的日期值获得命中。
Here's my property mapping: 这是我的属性映射:
{
"properties": {
"creationDate": {
"type": "date",
"format": "dd-MM-yyyy HH:mm:ss"
},
...
}
}
Here's the mapping in the java class: 这是java类中的映射:
@Field(type = Date, format = DateFormat.custom, pattern ="dd-MM-yyyy HH:mm:ss")
public Calendar creationDate;
The problem is when I try to search for an exact date: 问题是当我尝试搜索确切日期时:
GET test/searchableSo/_search
{
"query": {
"term": {
"creationDate": {
"value": "14-11-2014 05:55:46"
}
}
}
}
It doesn't return anything, only if I use the long equivalent: 它不返回任何东西,只有当我使用长的等价物时:
{
"query": {
"term": {
"creationDate": {
"value": "1415987746214"
}
}
}
}
Any insight? 任何见解?
Usually it is safer to use the range filter instead of term/match when dealing with date fields. 通常,在处理日期字段时使用范围过滤器而不是术语/匹配更安全。
Elasticsearch internally stores date type as a long value. Elasticsearch在内部将日期类型存储为long值。 So I believe passing 1415987746214 while indexing should end up storing the value as is.
所以我认为在索引时应该通过1415987746214最终应该按原样存储值。
Hence 1415987746214 is not the same as " 14-11-2014 05:55:46". 因此1415987746214与“ 14-11-2014 05:55:46”不同。 because of the millisecond portion.
因为毫秒部分。
Try indexing it without the millisecond portion ie " 1415987746000 " or you could use the numeric_resolution setting to be seconds in the mapping and specify timestamp in seconds since epoch while indexing ie 1415987746 尝试将其编入索引而不使用毫秒部分,即“ 1415987746000 ”,或者您可以使用numeric_resolution设置为映射中的秒数,并指定自索引以来的时间戳(以秒为单位),即1415987746
Example: 例:
"properties": { "creationDate": { "type": "date", "format": "dd-MM-yyyy HH:mm:ss" ,"numeric_resolution" : "seconds"},..}
either would work for the query : 要么适用于查询:
{ "query": { "term": { "creationDate": { "value": "14-11-2014 17:55:46" } } } }
remember to use the 24 hour clock. 记得使用24小时制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.