amazon-web-serviceselasticsearchrange-query

Range query for long type in aws elasticsearch


I am trying to query an elasticsearch index in AWS to get all entries with a mass attribute greater than 1000, the datatype for the attribute is Long.

I found the range query and have tried that (see example below) but it's returning nothing but when I use other queries they return attributes with mass greater than 1000 so they're definitely in the index.

This is the Range query I'm trying:

{
  "method": "POST",
  "index": "users",
  "type": "user",
  "path": "_search?filter_path=filter",
  "body": {
    "size": 20,
    "from": 0,
    "query": {
        "bool": {
            "must":[{
                "range": {
                  "mass": {
                    "gte": 1000
                  }
                }
            }]
        }

    }
  }
}

I'm not getting any error messages, just zero hits.


Solution

  • So the problem that's causing to get you zero hits is the filter_path parameter you specify in

    "path": "_search?filter_path=filter"
    

    As stated in the official documentation the filter_path parameter is part of the common options regarding the REST API's. That means you can always add that parameter.

    With Response Filtering you can reduce the response returned by Elasticsearch. Since you defined

    _search?filter_path=filter
    

    you probably get zero hits because there is no filter-element that can be returned.