Boost not working as expected in bool query


(mattcollins84) #1

Hi,

I am trying to run a bool query with a single "must" query and several "should" queries.

Each of the "should" queries are "term" queries and have a different boost applied to them, however I am not getting the output I would expect.

Here is my query:
{
"query" : {
"bool" : {
"must" : {
"term" : { "locations" : 1 }
},
"should" : [
{
"term" : { "tags" : { "value":1, "boost":10 } }
},
{
"term" : { "categories" : { "value":"c1", "boost":5 } }
}
],
"minimum_number_should_match" : 1
}
}
}

I would expect that this query would return in the following order:

  • all documents where locations contains 1, tags contains 1, categories contains "c1"
  • all documents where locations contains 1, tags contains 1
  • all documents where locations contains 1, categories contains "c1"

But what I am getting is:

  • all documents where locations contains 1, tags contains 1, categories contains "c1" (score of ~10)
  • all documents where locations contains 1, categories contains "c1" (score of ~7)
  • all documents where locations contains 1, tags contains 1 (score of ~0.5) <--- this seems really weird

I feel like I am missing something obvious, but am a bit of an ES novice - please help!

Here is my mapping:

curl -XPUT http://localhost:9200/goat/simple/_mapping -d'
{
"simple" : {
"properties" : {
"name" : {"type" : "string"},
"locations" : {"type" : "integer"},
"categories" : {"type" : "string"},
"tags" : {"type" : "integer"},
"sortcode" : {"type" : "integer"},
"isCustomer" : {"type" : "boolean"}
}
}
}'

Here is my sample data:

curl -XPUT http://localhost:9200/goat/simple/1 -d'{"name":"First Business","locations":[1],"categories":["c1"],"tags":[1],"sortcode":100,"isCustomer" :true}'
curl -XPUT http://localhost:9200/goat/simple/2 -d'{"name":"Second Business","locations":[1],"categories":["c1"],"tags":[],"sortcode":100,"isCustomer" :true}'
curl -XPUT http://localhost:9200/goat/simple/3 -d'{"name":"Third Business","locations":[1],"categories":[],"tags":[1],"sortcode":100,"isCustomer" :true}'
curl -XPUT http://localhost:9200/goat/simple/4 -d'{"name":"Fourth Business","locations":[1,2],"categories":["c1"],"tags":[1],"sortcode":200,"isCustomer" :true}'
curl -XPUT http://localhost:9200/goat/simple/5 -d'{"name":"Fifth Business","locations":[1,2],"categories":["c1"],"tags":[],"sortcode":200,"isCustomer" :true}'
curl -XPUT http://localhost:9200/goat/simple/6 -d'{"name":"Sixth Business","locations":[1,2],"categories":[],"tags":[1],"sortcode":200,"isCustomer" :true}'
curl -XPUT http://localhost:9200/goat/simple/7 -d'{"name":"Seventh Business","locations":[1,2,3],"categories":["c1"],"tags":[1],"sortcode":400,"isCustomer" :false}'
curl -XPUT http://localhost:9200/goat/simple/8 -d'{"name":"Eighth Business","locations":[1,2,3],"categories":["c1"],"tags":[],"sortcode":400,"isCustomer" :false}'
curl -XPUT http://localhost:9200/goat/simple/9 -d'{"name":"Ninth Business","locations":[1,2,3],"categories":[],"tags":[1],"sortcode":400,"isCustomer" :false}'

Thanks in advance!
Matt


(system) #2