# Customize score when fields are missing

**URL:** <https://discuss.elastic.co/t/customize-score-when-fields-are-missing/8463>\
**Category:** Elasticsearch\
**Created:** [July 19, 2012, 9:43am UTC](https://discuss.elastic.co/t/customize-score-when-fields-are-missing/8463 "2012-07-19T09:43:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crwe\_2](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@Crwe\_2](https://discuss.elastic.co/u/Crwe_2)\
**Post date:** [July 19, 2012, 9:43am UTC](https://discuss.elastic.co/t/customize-score-when-fields-are-missing/8463/1 "2012-07-19T09:43:03Z")

</div>

Hello all,

I'd like to _demote_ documents that are missing a specific field (either  
"url" or "custom-url"), because documents with URLs are more relevant.  
(Or, equivalently, promote documents that contain at least one of these  
fields.)

How can this be achieved in ElasticSearch?

---

<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 19, 2012, 9:56am UTC](https://discuss.elastic.co/t/customize-score-when-fields-are-missing/8463/2 "2012-07-19T09:56:17Z")

</div>

On Thu, 2012-07-19 at 02:43 -0700, Crwe wrote:

> Hello all,
> 
> I'd like to _demote_ documents that are missing a specific field  
> (either "url" or "custom-url"), because documents with URLs are more  
> relevant.  
> (Or, equivalently, promote documents that contain at least one of  
> these fields.)

curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
{  
"query" : {  
"custom\_filters\_score" : {  
"query" : {  
"text" : {  
"title" : "search keywords"  
}  
},  
"filters" : [  
{  
"boost" : "2",  
"filter" : {  
"exists" : {  
"field" : "url"  
}  
}  
}  
]  
}  
}  
}  
'

---

<div class="post-metadata">

**Author:** ![Crwe\_2](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@Crwe\_2](https://discuss.elastic.co/u/Crwe_2)\
**Post date:** [July 19, 2012, 1:22pm UTC](https://discuss.elastic.co/t/customize-score-when-fields-are-missing/8463/3 "2012-07-19T13:22:20Z")

</div>

Muchas gracias senor Gormley, exactly what I needed! I guess the "either  
url or custom-url" part can be accomplished using an OR filter with two  
"exists" parts.

On Thursday, July 19, 2012 11:56:17 AM UTC+2, Clinton Gormley wrote:

> On Thu, 2012-07-19 at 02:43 -0700, Crwe wrote:
> 
> > Hello all,
> > 
> > I'd like to _demote_ documents that are missing a specific field  
> > (either "url" or "custom-url"), because documents with URLs are more  
> > relevant.  
> > (Or, equivalently, promote documents that contain at least one of  
> > these fields.)
> 
> curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
> {  
> "query" : {  
> "custom\_filters\_score" : {  
> "query" : {  
> "text" : {  
> "title" : "search keywords"  
> }  
> },  
> "filters" : [  
> {  
> "boost" : "2",  
> "filter" : {  
> "exists" : {  
> "field" : "url"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> '

---

<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, 3:19am UTC](https://discuss.elastic.co/t/customize-score-when-fields-are-missing/8463/4 "2017-07-06T03:19:49Z")

</div>


