1

Is it possible to save time fields in elastic search, in format like HH:mm and search then based on some time query range like HH:mm-HH:mm?

1 Answer 1

2

Yes, you can store time in elastic in this format check the related doc about the different date format here:

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html

 hour_minute or strict_hour_minute
    A formatter for a two digit hour of day and two digit minute of hour: HH:mm.

You will have a mapping like this if you use the build in format:

PUT my_index
{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date",
        "format": "hour_minute"
      }
    }
  }
}

To search you can use the build in format in your range query.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

GET /_search
{
    "query": {
        "range" : {
            "age" : {
                "gte" : "10:15",
                "lte" : "20:13",
                "format" : "hour_minute"
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much :)

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.