elasticsearch - If I store a date in elastic search using a timestamp (e.g. 1428956853627), can I still query that record by day, without the time value? -


for example, if have mapping date field like:

$ curl -xget http://localhost:9200/testing/blog/_mapping {"testing":{   "mappings":{     "blog":{       "properties":{          "posted":{            "type":"date",            "format":"dateoptionaltime"          },           "title":{            "type":"string"          }        }      }    }  } } 

and insert record like:

$ curl -xput http://localhost:9200/testing/blog/1 -d  '{"title": "elastic search", "posted": 1428956853627}' {"_index":"testing","_type":"blog","_id":"1","_version":1,"created":true} 

using timestamp corresponding mon apr 13 15:27:33 cdt 2015, there way query out "plain old" date? instance, if want see posts posted on 4/13/15, try:

$ curl -xget http://localhost:9200/testing/blog/_search?pretty -d  '{"query":{"filtered": {"filter": {"term": {"posted": "2015-04-13"}}}}}' 

and no hits:

{   "took" : 1,   "timed_out" : false,   "_shards" : {     "total" : 5,     "successful" : 5,     "failed" : 0   },   "hits" : {     "total" : 0,     "max_score" : null,     "hits" : [ ]   } } 

even if do include timestamp in query, still don't record:

$ curl -xget http://localhost:9200/testing/blog/_search?pretty -d  '{"query": {"filtered": {"filter": {"term": {"posted": "2015-04-13t15:27:33"}}}}}' 

i thought @ least, since mapping declared "posted" date, retrieve range via:

$ curl -xget http://localhost:9200/testing/blog/_search?pretty -d  '{"query": {"filtered": {"filter": {"range": {"posted": {"gt": "2014-04-13", "lt": "2014-04-15"}}}}}}' 

but doesn't work. way can seem query entry date using exact same timestamp (long) value passed in:

$ curl -xget http://localhost:9200/testing/blog/_search?pretty -d  '{"query": {"filtered": {"filter": {"term": {"posted": 1428956853627}}}}}' 

but that's not useful... have convert of dates strings before inserting them elastic search? ideally i'd able save higher fidelity, including times in case need them, still search 2014-04-13. can elasticsearch that?

the date range query way go with.

{   "query": {     "filtered": {       "filter": {         "range": {           "posted": {             "gt": "2015-04-13",             "lt": "2015-04-15"           }         }       }     }   } } 

the date provided year 2015 , not 2014 have done in query. why range query not working. es accepting time format because been covered under formats specified under dateoptionaltime. check if need see usable formats here. if need other formats accepted , need mention additional ones in mappings.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -