Disable Coord in Bool query with query DSL


(Jacob Robertson-2) #1

I am using a bool query to combine several dis_max queries. I was
getting some results in a rather unexpected order and went to check
out the JSON returned by elasticsearch. Much to my surprise, on about
half of the documents coming out of this bool query, the coord factor
was not being applied. First of all assuming my query json is well-
formed, this is rather inconsistent. Additionally is there a way with
the query DSL to disable coord much like Lucene's BooleanQuery. The
query I am sending to elasticsearch looks something like this

{
"query":{
"bool":{
"should":[{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"foo"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"foo"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"foo"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"foo"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"foo"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"foo"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"foo"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"foo"
}
}
},
"boost":1.7000000000000002
}
}]
}
},{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"bar"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"bar"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"bar"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"bar"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"bar"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"bar"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"bar"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"bar"
}
}
},
"boost":1.7000000000000002
}
}]
}
}]
}
}
}


(Shay Banon) #2

Where do you see coord being disabled? You can control it in elasticsearch
for boolean queries, but, by default, it is true.

-shay.banon

On Wed, Jul 14, 2010 at 6:20 PM, Jacob Robertson <
g.jacob.robertson@gmail.com> wrote:

I am using a bool query to combine several dis_max queries. I was
getting some results in a rather unexpected order and went to check
out the JSON returned by elasticsearch. Much to my surprise, on about
half of the documents coming out of this bool query, the coord factor
was not being applied. First of all assuming my query json is well-
formed, this is rather inconsistent. Additionally is there a way with
the query DSL to disable coord much like Lucene's BooleanQuery. The
query I am sending to elasticsearch looks something like this

{
"query":{
"bool":{
"should":[{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"foo"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"foo"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"foo"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"foo"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"foo"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"foo"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"foo"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"foo"
}
}
},
"boost":1.7000000000000002
}
}]
}
},{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"bar"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"bar"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"bar"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"bar"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"bar"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"bar"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"bar"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"bar"
}
}
},
"boost":1.7000000000000002
}
}]
}
}]
}
}
}


(Jacob Robertson-2) #3

That was my problem. I didn't see anything about coord being disabled
in ES. In Lucene it's fairly clearly documented with things like the
BooleanQuery(boolean disableCoord) constructor. I saw nothing
regarding it at all in the documentation for the query DSL. I figured
out by trial and error that I could set "disableCoord" : true in the
bool query, but that was not the product of documentation. Nonetheless
it was inconsistent without that line, with half of the documents
having scores that had been multiplied through by coord, and the other
half not.

On Jul 14, 1:39 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Where do you see coord being disabled? You can control it in elasticsearch
for boolean queries, but, by default, it is true.

-shay.banon

On Wed, Jul 14, 2010 at 6:20 PM, Jacob Robertson <

g.jacob.robert...@gmail.com> wrote:

I am using a bool query to combine several dis_max queries. I was
getting some results in a rather unexpected order and went to check
out the JSON returned by elasticsearch. Much to my surprise, on about
half of the documents coming out of this bool query, the coord factor
was not being applied. First of all assuming my query json is well-
formed, this is rather inconsistent. Additionally is there a way with
the query DSL to disable coord much like Lucene's BooleanQuery. The
query I am sending to elasticsearch looks something like this

{
"query":{
"bool":{
"should":[{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"foo"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"foo"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"foo"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"foo"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"foo"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"foo"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"foo"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"foo"
}
}
},
"boost":1.7000000000000002
}
}]
}
},{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"bar"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"bar"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"bar"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"bar"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"bar"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"bar"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"bar"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"bar"
}
}
},
"boost":1.7000000000000002
}
}]
}
}]
}
}
}


(Shay Banon) #4

I see, you wanted to disable coord for the boolean query. Yea, I forgot to
add it to the boolean query doc. Added.

-shay.banon

On Wed, Jul 14, 2010 at 9:42 PM, Jacob Robertson <
g.jacob.robertson@gmail.com> wrote:

That was my problem. I didn't see anything about coord being disabled
in ES. In Lucene it's fairly clearly documented with things like the
BooleanQuery(boolean disableCoord) constructor. I saw nothing
regarding it at all in the documentation for the query DSL. I figured
out by trial and error that I could set "disableCoord" : true in the
bool query, but that was not the product of documentation. Nonetheless
it was inconsistent without that line, with half of the documents
having scores that had been multiplied through by coord, and the other
half not.

On Jul 14, 1:39 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Where do you see coord being disabled? You can control it in
elasticsearch
for boolean queries, but, by default, it is true.

-shay.banon

On Wed, Jul 14, 2010 at 6:20 PM, Jacob Robertson <

g.jacob.robert...@gmail.com> wrote:

I am using a bool query to combine several dis_max queries. I was
getting some results in a rather unexpected order and went to check
out the JSON returned by elasticsearch. Much to my surprise, on about
half of the documents coming out of this bool query, the coord factor
was not being applied. First of all assuming my query json is well-
formed, this is rather inconsistent. Additionally is there a way with
the query DSL to disable coord much like Lucene's BooleanQuery. The
query I am sending to elasticsearch looks something like this

{
"query":{
"bool":{
"should":[{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"foo"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"foo"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"foo"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"foo"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"foo"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"foo"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"foo"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"foo"
}
}
},
"boost":1.7000000000000002
}
}]
}
},{
"dis_max":{
"queries":[{
"constant_score":{
"filter":{
"query":{
"prefix":{
"school":"bar"
}
}
},
"boost":1.0
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"school":"bar"
}
}
},
"boost":1.4
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"username":"bar"
}
}
},
"boost":1.1
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"username":"bar"
}
}
},
"boost":1.5
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"lastname":"bar"
}
}
},
"boost":1.2000000000000002
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"lastname":"bar"
}
}
},
"boost":1.6
}
},{
"constant_score":{
"filter":{
"query":{
"prefix":{
"firstname":"bar"
}
}
},
"boost":1.3000000000000003
}
},{
"constant_score":{
"filter":{
"query":{
"term":{
"firstname":"bar"
}
}
},
"boost":1.7000000000000002
}
}]
}
}]
}
}
}


(system) #5