# Boosting query and null values

**URL:** <https://discuss.elastic.co/t/boosting-query-and-null-values/4769>\
**Category:** Elasticsearch\
**Created:** [July 4, 2011, 11:17am UTC](https://discuss.elastic.co/t/boosting-query-and-null-values/4769 "2011-07-04T11:17:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Reelsen](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alexander\_Reelsen](https://discuss.elastic.co/u/Alexander_Reelsen)\
**Post date:** [July 4, 2011, 11:17am UTC](https://discuss.elastic.co/t/boosting-query-and-null-values/4769/1 "2011-07-04T11:17:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 4, 2011, 11:25am UTC](https://discuss.elastic.co/t/boosting-query-and-null-values/4769/2 "2011-07-04T11:25:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:01am UTC](https://discuss.elastic.co/t/boosting-query-and-null-values/4769/3 "2017-07-06T04:01:52Z")

</div>


