elasticsearch in java code example

Example 1: implement elasticsearch filter in java

//QUERY IN ES
{
  "size": 100, //default 10
  "from": 0, //default 0
  "query":
   {
    "match_all": {}
   },
   "filter" : {
        "term" : { 
            "activated" : "true" 
        }
    }
}  


//QUERY IN JAVA
FilteredQueryBuilder builder = 
 QueryBuilders.filteredQuery(QueryBuilders.termQuery("test", 
 "test"),FilterBuilders.termFilter("key","value"));

Example 2: implement elasticsearch filter in java

FilteredQueryBuilder builder = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
   FilterBuilders.termFilter("username","stackoverflow"));

Tags:

Java Example