2

My elasticsearch has data, particularly something like this for dates:

{
  "startTime": {
    "type": "string",
    "format": "yyyy/MM/dd",
    "index": "analyzed",
    "analyzer": "keyword"
  }
}

I am adding a date range picker and want to use the dates picked to go query elasticsearch for data with startTime inside this range chosen. I'm not sure how to structure this query to elasticsearch, or if it will even work with this being a string field (I can potentially change it, though).

can anyone help me here?

1 Answer 1

6

Your field is a string, the format property is ignored. You should change your mapping and use the date type. Have a look here to see the core types available in elasticsearch.

I would use a filter instead of a query. It will be cached, thus faster. The following is an example for the last 7 days:

{
    "filter" : {
        "range" : {
            "PublishTime" : {
                "from" : "20130505T000000",
                "to" : "20131105T235959"
            }
        }
    }
}

Note that if you use the filter like this it's going to be the same filter the whole day, thus you would make good use of the cache.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.