Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtered Query in Elasticsearch Java API

I am little bit confused while creating Filtered query in Elasticsearch Java API. SearchRequestBuilder class has setPostFilter method, javadoc of this method clearly says that filter will be applied after Query is executed.

However, there is no setFilter method Or some other method which will allow to apply filter before
query is executed. How do I create filtered Query(which basically applies filter before query is executed) here? Am I missing something?

like image 470
Sagar Avatar asked May 12 '14 01:05

Sagar


1 Answers

 FilteredQueryBuilder builder =   QueryBuilders.filteredQuery(QueryBuilders.termQuery("test",   "test"),FilterBuilders.termFilter("test","test")); 

It will build the filtered query...To filteredQuery, first argument is query and second arguments is Filter.

Update: Filtered query is depreciated in elasticsearch 2.0+.refer

Hope it helps..!

like image 63
BlackPOP Avatar answered Oct 19 '22 23:10

BlackPOP