I am confused by the postFilter and filter of elasticsearch‘s java client

AFAIK, There are three types search I can perform on elasticsearch:

  1. query => which will do scoring and affect the hit
  2. filter => which will not do scoring and affect the hit
  3. post_filter => which will be applied on the result of query/filter and
    will not affect the hit and facet aggregation

At the java client library side, I am assuming there should be same three
types of apis existing, yes I found three.
But unfortunately the setFilter method of SearchRequestBuilder had been
marked as deprecated and also had
been delegated to the setPostFilter method of itself.

My question is how can I perform a filter query by java client? I found a
way by that I can do filter query as following:

search.setQuery(
QueryBuilders.filteredQuery(
QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("xx", "v")
)
);

But it seems so strange that I have to declare an unnecessary match all
query.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6aefc449-3997-4128-b9ee-715d7a998b5c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

That looks correct to me.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4ad78d4d-3e0f-4dfe-a4b9-1d59c349e56e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

If you only need the filter part you can use a constant score query that
only contains a filter, in that case you wouldn't need the match_all query
anymore.

On Friday, February 28, 2014 10:04:35 AM UTC+1, xzer LR wrote:

AFAIK, There are three types search I can perform on elasticsearch:

  1. query => which will do scoring and affect the hit
  2. filter => which will not do scoring and affect the hit
  3. post_filter => which will be applied on the result of query/filter and
    will not affect the hit and facet aggregation

At the java client library side, I am assuming there should be same three
types of apis existing, yes I found three.
But unfortunately the setFilter method of SearchRequestBuilder had been
marked as deprecated and also had
been delegated to the setPostFilter method of itself.

My question is how can I perform a filter query by java client? I found a
way by that I can do filter query as following:

search.setQuery(
QueryBuilders.filteredQuery(
QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("xx", "v")
)
);

But it seems so strange that I have to declare an unnecessary match all
query.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0ec29ae2-fc52-4ebe-b83e-a94b3ea775d2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.