简体   繁体   English

elasticsearch-如何找到确切的日期类型值?

[英]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.

相关问题 弹性搜索弹簧不返回完全匹配 - elasticsearch spring not return exact match 如何使用Spring Data Cassandra将java.util.Date值插入Cassandra日期类型列中? - How to insert java.util.Date values into Cassandra date type column using Spring Data Cassandra? Spring 数据 Elasticsearch 按字段查找和最新日期查询 - Spring data Elasticsearch find by field and latest date query Spring Data Elasticsearch仅返回完全匹配 - Spring Data Elasticsearch only returning exact matches 如何在Spring中将ElasticSearch模型字段标记为关键字类型? - How to mark ElasticSearch model field as KeyWord type in Spring? Hibernate Search + Elasticsearch - 请求中的version_type - 如何实现 - Hibernate Search + Elasticsearch - version_type in requests - how to implement ElasticSearch Boost 归档并按日期排序 - ElasticSearch Boost filed and sort by date Crudrepository如何在最后日期之间找到? - Crudrepository How to find by last date between? 如何读取输入类型=“日期”到java对象日期? - How to read input type="date" to java object Date? 如何转换 SearchHits<t> 返回页面类型<t> spring 数据 elasticsearch 4.0 中的返回类型</t></t> - How to convert SearchHits<T> return type to Page<T> return type in spring data elasticsearch 4.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM