To provide the result of two queries to Filter


(arien) #1

Hi;
I am Using Two queries

QueryBuilder qb1=textQuery("Subject", "Biometric");
QueryBuilder qb2=textPhraseQuery("Subject", "Biometric");
Filterbuilder fb =FilterBuilders.termFilter("UsersOnMail",
"ajay.padvi")

And in SearchRequestBuilder I want to give the result of qb1 AND qb2
to FilterBuilder fb.Here I am able to provide single query either qb1
or qb2;
SearchRequestBuilder request =
client.prepareSearch(index).setFilter(fb).setTypes(mapping).setQuery(qb1);

But i want this filter to be applied to results of both qb1 and qb2.
Please Help me with this.

Thanks;


(Shay Banon) #2

Create a bool filter and add qb1 and qb2 as either must or should clauses
(not sure which behavior you want between the two). Then, use a
filteredQuery, provide the bool query you have to it, and the filter you
create as the filter.

On Mon, Oct 24, 2011 at 10:59 AM, arien ajaypadvi@gmail.com wrote:

Hi;
I am Using Two queries

QueryBuilder qb1=textQuery("Subject", "Biometric");
QueryBuilder qb2=textPhraseQuery("Subject", "Biometric");
Filterbuilder fb =FilterBuilders.termFilter("UsersOnMail",
"ajay.padvi")

And in SearchRequestBuilder I want to give the result of qb1 AND qb2
to FilterBuilder fb.Here I am able to provide single query either qb1
or qb2;
SearchRequestBuilder request =
client.prepareSearch(index).setFilter(fb).setTypes(mapping).setQuery(qb1);

But i want this filter to be applied to results of both qb1 and qb2.
Please Help me with this.

Thanks;


(arien) #3

Thank you shay,filteredQuery helped me achieving expected results.

On Tue, Oct 25, 2011 at 4:08 AM, Shay Banon kimchy@gmail.com wrote:

Create a bool filter and add qb1 and qb2 as either must or should clauses
(not sure which behavior you want between the two). Then, use a
filteredQuery, provide the bool query you have to it, and the filter you
create as the filter.

On Mon, Oct 24, 2011 at 10:59 AM, arien ajaypadvi@gmail.com wrote:

Hi;
I am Using Two queries

QueryBuilder qb1=textQuery("Subject", "Biometric");
QueryBuilder qb2=textPhraseQuery("Subject", "Biometric");
Filterbuilder fb =FilterBuilders.termFilter("UsersOnMail",
"ajay.padvi")

And in SearchRequestBuilder I want to give the result of qb1 AND qb2
to FilterBuilder fb.Here I am able to provide single query either qb1
or qb2;
SearchRequestBuilder request =
client.prepareSearch(index).setFilter(fb).setTypes(mapping).setQuery(qb1);

But i want this filter to be applied to results of both qb1 and qb2.
Please Help me with this.

Thanks;


(system) #4