Boosting query and null values


(Alexander Reelsen) #1

Hi there,

I just played around with the boosting query to demote some results,
but I had trouble getting it up and running.
I am trying to demote results, which do not have a certain field set.
I could also do this using a script and ranking it down (which works
perfectly) but I thought, this is what a boosting query is for.

curl -XPOST "localhost:9200/foo/product/_search?pretty=true" -d '
{
"query" : {
"boosting" : {
"positive" : {
"term" : {
"ProductName" : "test"
}
},
"negative" : {
"term" : {
"imageUrl" : null
}
},
"negative_boost" : 0.5
}
}
}
'

This returns all results matching the positive query with exact the
same score as done with a normal query. Anything obvious I have done
wrong or is boosting for "null" or none values simply not possible
this way?

Many thanks for helping!

--Alexander


(Clinton Gormley) #2

Hi Alexander

I am trying to demote results, which do not have a certain field set.
I could also do this using a script and ranking it down (which works
perfectly) but I thought, this is what a boosting query is for.

for your null clause, you want to use the "missing" filter, which needs
to be wrapped in a constant_score query:

curl -XPOST "localhost:9200/foo/product/_search?pretty=true" -d '
{
"query" : {
"boosting" : {
"positive" : {
"term" : {
"ProductName" : "test"
}
},
"negative" : {
"constant_score" : {
"filter: {
"missing": { "field": "imageUrl" }
}
}
},
"negative_boost" : 0.5
}
}
}
'

clint


(system) #3