Wednesday 2 December 2015

Elasticsearch: Java: range query

Range query is used to perform operations like greater than(>), less than (<), greater than or equal to (>=) and less than or equal to (<=).

Range query accepts below parameters.

Parameter
Meaning
gte
Greater than or equal to
gt
Greater than
lte
Less than or equal to
lt
Less than

{
  "query":{
    "range" : {
      "age" : {
        "gte" : 10,
        "lte" : 20,
        "boost" : 2.0
        }
    }
  }
}

Above query return all document where age is >= 10 and <= 20.

Note:
Range query also accepts ‘boost’ as parameter.  ‘boost’ parameter sets the boost value of the query, defaults to 1.0

QueryBuilder builder = QueryBuilders.rangeQuery("age").gte(10).lte(20);

Above java statement generates following json query.
{
  "range" : {
    "age" : {
      "from" : 10,
      "to" : 20,
      "include_lower" : true,
      "include_upper" : true
    }
  }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment