Best way to build filter for query using FilterBuilder methods?


(david webb) #1

Hello guys,

I'm new to this, please excuse me if this sounds like a dumb
questions. I'm still trying to figure it out how the java API works.

So I'm in need of build filters for my query (I've got between 0 to 5
filters) per search. And I'm using and "AndFilter.add" method to mix
them if they were passed as a search filter.

I found out it works just fine if I've got 2 or more filters. But I've
noticed that if I only pass one filter the generated JSON query fails
since it ends building up something like

filter: {
filters: { one_filter_here}
}

And ES doesn't like that.

What's the best strategy to build those filters so it has the
intelligence of just throw "filter" if one argument is passed, and
fitler: {filters: ..}} if more that one is passed?


(Shay Banon) #2

Which client are you using? Can you gist the full search request that fails? The and filter can support a single filter, but it needs to exists within an array still.

On Tuesday, January 31, 2012 at 12:12 AM, david webb wrote:

Hello guys,

I'm new to this, please excuse me if this sounds like a dumb
questions. I'm still trying to figure it out how the java API works.

So I'm in need of build filters for my query (I've got between 0 to 5
filters) per search. And I'm using and "AndFilter.add" method to mix
them if they were passed as a search filter.

I found out it works just fine if I've got 2 or more filters. But I've
noticed that if I only pass one filter the generated JSON query fails
since it ends building up something like

filter: {
filters: { one_filter_here}
}

And ES doesn't like that.

What's the best strategy to build those filters so it has the
intelligence of just throw "filter" if one argument is passed, and
fitler: {filters: ..}} if more that one is passed?


(david webb) #3

Thanks Shay

I think I found the problem, it was related to a filter but in my
facet it was going empty.

Cheers

David

On Jan 31, 10:57 am, Shay Banon kim...@gmail.com wrote:

Which client are you using? Can you gist the full search request that fails? The and filter can support a single filter, but it needs to exists within an array still.

On Tuesday, January 31, 2012 at 12:12 AM, david webb wrote:

Hello guys,

I'm new to this, please excuse me if this sounds like a dumb
questions. I'm still trying to figure it out how the java API works.

So I'm in need of build filters for my query (I've got between 0 to 5
filters) per search. And I'm using and "AndFilter.add" method to mix
them if they were passed as a search filter.

I found out it works just fine if I've got 2 or more filters. But I've
noticed that if I only pass one filter the generated JSON query fails
since it ends building up something like

filter: {
filters: { one_filter_here}
}

And ES doesn't like that.

What's the best strategy to build those filters so it has the
intelligence of just throw "filter" if one argument is passed, and
fitler: {filters: ..}} if more that one is passed?


(system) #4