Wondering Coder
Wondering Coder

Reputation: 1702

Filtering in Elastic Search?

I'm using date_histogram api to get the actual count using the interval (hour/day/week or month). Also I have a feature which I'm having trouble implementing, a user can filter the results by entering an startDate and endDate (textbox) which will be queried using a field timestamp. So how can I filter the results by querying only one field (which is TIMESTAMP) while using date_histogram api or any api so I can achieve my desire result.

In SQL I will just use a between operator to get the result but from what I've read so far their is no BETWEEN operator in Elastic Search (not sure).

I have this script so far:

curl 'http://anotherdomain.com:9200/myindex/_search?pretty=true' -d '{
               "query" : { 
                  "filtered" : { 
                     "filter" : { 
                        "exists" : { 
                           "field" : "adid" 
                        } 
                     }, 
                     "query" : { 
                        "query_string" : {
                          "fields" : [
                            "adid", "imp"
                            ],
                            "query" : "525826 AND true"
                        }
                     }

                  } 
               },
               "facets" : {
                  "histo1":{
                    "date_histogram":{
                      "field":"timestamp",
                      "interval":"day"
                    }
                  }
                } 
            }'

Upvotes: 1

Views: 682

Answers (1)

imotov
imotov

Reputation: 30163

In elasticsearch you can use range query of filter to achieve that.

Upvotes: 2

Related Questions