Apurva
Apurva

Reputation: 69

elasticsearch query to get records between particular date using curl

curl -X GET 'http://xxx.xxx.x.xx:9200/upslinklog/upslinklog/_search?pretty' -d '{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "range": {
                    "logTimestamp": {
                        "gte": "2017/05/17", 
            "lte":"2017/05/18"
                "format": "yyyy/mm/dd"
                    }
                }
            }

    }
}
'

I want to records after 17/5/2017.Above query code gave all the records rather than some. How to do range query for filtered data

Upvotes: 1

Views: 2670

Answers (1)

Mickael
Mickael

Reputation: 4558

First, you have to specify your logTimestamp as a date in your index configuration.

From Elasticsearch documentation "Date datatype" :

Example of index configuration :

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "date": {
          "type": "date" 
        }
      }
    }
  }
}

Then you can use simple Range Query as following :

GET _search
{
    "query": {
        "range" : {
            "born" : {
                "gte": "01/01/2012",
                "lte": "01/01/2013",
                "format": "dd/MM/yyyy"
            }
        }
    }
}

Upvotes: 1

Related Questions