I want to use existQuery
in my Java code. We're using Elasticsearch 2.0.
Should I wrap the query as a filter using constantScoreQuery
? (as shown by the Query DSL documentation)
The code snippet will be something like this:
//instantiate Elasticsearch client
Client client = .....; //code omitted for brevity
QueryBuilder locationExist = QueryBuilders
.constantScoreQuery(QueryBuilders.existsQuery("location"));
SearchRequestBuilder srb = client.prepareSearch(index).setTypes(type)
.setSearchType(SearchType.SCAN)
.setQuery(locationExist)
.setSize(100);
Or, can I use it directly? As shown in code snippet below:
QueryBuilder locationExist = QueryBuilders.existsQuery("location");
SearchRequestBuilder srb = client.prepareSearch(index).setTypes(type)
.setSearchType(SearchType.SCAN)
.setQuery(locationExist)
.setSize(100);