Possible bug in BoolQueryBuilder - can't get multiple 'should' queries to work


(Ellery Crane-2) #1

I'm trying to build a bool query that has multiple 'should' queries
using the Java API (or the groovy API, for that matter), but it isn't
working. I threw together a spock specification to test the behavior
and confirmed it seems to be constructing the should clauses
incorrectly. The spec is here:

It appears that the builder is adding multiple 'should' properties,
and then aggregating their contents incorrectly. In the spec above,
the query generates the following JSON:

{
"bool": {
"should": {
"query_string": {
"query": "charles",
"fields": ["user.name.first", "user.email",
"user.name.last", "user.email"],
"use_dis_max": true
}
},
"should": {
"query_string": {
"query": "xavier",
"use_dis_max": true
}
}
}
}

However, it should instead be generating something like the following:

{
"bool": {
"should": {
{
"query_string": {
"query": "charles",
"fields": ["user.name.first", "user.email"],
"use_dis_max": true
}
},
{
"query_string": {
"query": "xavier",
"fields": ["user.name.last", "user.email"],
"use_dis_max": true
}
}
}
}
}

As an additional note, I only tried the Java api after I couldn't get
the Groovy dsl to work at all for should clauses. It might be related
to the same bug, but perhaps not. Could anyone post an example of how
to construct a bool query with multiple 'should' queries using the
Groovy query DSL?


(Shay Banon) #2

The generated json (though not formally json, since it has several elements with the same name, like "should") is fine when it comes to elasticsearch (it supports that in its parsing stage).
On Monday, May 16, 2011 at 8:17 PM, Ellery Crane wrote:

I'm trying to build a bool query that has multiple 'should' queries
using the Java API (or the groovy API, for that matter), but it isn't
working. I threw together a spock specification to test the behavior
and confirmed it seems to be constructing the should clauses
incorrectly. The spec is here:

https://gist.github.com/974865

It appears that the builder is adding multiple 'should' properties,
and then aggregating their contents incorrectly. In the spec above,
the query generates the following JSON:

{
"bool": {
"should": {
"query_string": {
"query": "charles",
"fields": ["user.name.first", "user.email",
"user.name.last", "user.email"],
"use_dis_max": true
}
},
"should": {
"query_string": {
"query": "xavier",
"use_dis_max": true
}
}
}
}

However, it should instead be generating something like the following:

{
"bool": {
"should": {
{
"query_string": {
"query": "charles",
"fields": ["user.name.first", "user.email"],
"use_dis_max": true
}
},
{
"query_string": {
"query": "xavier",
"fields": ["user.name.last", "user.email"],
"use_dis_max": true
}
}
}
}
}

As an additional note, I only tried the Java api after I couldn't get
the Groovy dsl to work at all for should clauses. It might be related
to the same bug, but perhaps not. Could anyone post an example of how
to construct a bool query with multiple 'should' queries using the
Groovy query DSL?


(Ellery Crane-2) #3

I get an error when I try to run it. Also, the query json that it
generates is wrong: it puts all the fields into the first should
query, instead of putting each field in the query it was a part of.

On May 16, 3:46 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

The generated json (though not formally json, since it has several elements with the same name, like "should") is fine when it comes to elasticsearch (it supports that in its parsing stage).

On Monday, May 16, 2011 at 8:17 PM, Ellery Crane wrote:

I'm trying to build a bool query that has multiple 'should' queries
using the Java API (or the groovy API, for that matter), but it isn't
working. I threw together a spock specification to test the behavior
and confirmed it seems to be constructing the should clauses
incorrectly. The spec is here:

https://gist.github.com/974865

It appears that the builder is adding multiple 'should' properties,
and then aggregating their contents incorrectly. In the spec above,
the query generates the following JSON:

{
"bool": {
"should": {
"query_string": {
"query": "charles",
"fields": ["user.name.first", "user.email",
"user.name.last", "user.email"],
"use_dis_max": true
}
},
"should": {
"query_string": {
"query": "xavier",
"use_dis_max": true
}
}
}
}

However, it should instead be generating something like the following:

{
"bool": {
"should": {
{
"query_string": {
"query": "charles",
"fields": ["user.name.first", "user.email"],
"use_dis_max": true
}
},
{
"query_string": {
"query": "xavier",
"fields": ["user.name.last", "user.email"],
"use_dis_max": true
}
}
}
}
}

As an additional note, I only tried the Java api after I couldn't get
the Groovy dsl to work at all for should clauses. It might be related
to the same bug, but perhaps not. Could anyone post an example of how
to construct a bool query with multiple 'should' queries using the
Groovy query DSL?


(Ellery Crane-2) #4

On May 16, 4:05 pm, Ellery Crane seid...@gmail.com wrote:

I get an error when I try to run it. Also, the query json that it
generates is wrong: it puts all the fields into the first should
query, instead of putting each field in the query it was a part of.

Disregard that, evidently- chalk this up to user error :slight_smile: The fields
issue was because there was a bug in my test code. I was, however,
seeing exceptions when building a similar query yesterday- I can no
longer produce them today, however; the code hasn't changed, but I am
no longer seeing the errors. Perhaps something in my environment went
awry; if I see them again, I will post a stack trace.

However, if anyone can point me to an example of how to do a should
query using the Groovy DSL, I'd still be interested.


(system) #5