# Distance feature query that weights null values lower

**URL:** <https://discuss.elastic.co/t/distance-feature-query-that-weights-null-values-lower/381956>\
**Category:** Elasticsearch\
**Created:** [September 15, 2025, 2:18pm UTC](https://discuss.elastic.co/t/distance-feature-query-that-weights-null-values-lower/381956 "2025-09-15T14:18:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jorgenfu](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jorgenfu](https://discuss.elastic.co/u/jorgenfu)\
**Post date:** [September 15, 2025, 2:18pm UTC](https://discuss.elastic.co/t/distance-feature-query-that-weights-null-values-lower/381956/1 "2025-09-15T14:18:57Z")

</div>

I’m looking for a way to weights documents higher based on a date field called `publicationDate`, but where the weight is lowest if the date field is null, instead of highest.

The full query is a bool query with several should-clauses where I’m trying to add a last clause that will prioritize documents for which the field `publicationDate` is newer.

My initial attempt almost works (simplified version):

```  
{  
"query": {  
"bool": {  
"minimum\_should\_match": 1,  
"should": [  
{  
"multi\_match": {  
"fields": ["title.standard^1.5", "originalTitle.standard^0.8"],  
"query": "something",  
"\_name": "titles",  
"boost": 2,  
"type": "cross\_fields"  
}  
},  
{  
"distance\_feature": {  
"field": "publicationDate",  
"origin": "now",  
"pivot": "913d",  
"boost": 0.5  
}  
}  
]  
}  
}  
}  
```

Except that documents with `publicationDate: null` end up on top. I’ve tried several things but none that work, for example changing the last clause to:

```  
{  
"bool": {  
"minimum\_should\_match": 1,  
"boost": 0.5,  
"filter": {  
"exists": {  
"field": "publicationDate"  
}  
},  
"should": {  
"distance\_feature": {  
"field": "publicationDate",  
"origin": "now",  
"pivot": "913d"  
}  
}  
}  
}  
```

I’ve also tried `must` instead of `filter` and shuffling around the clauses and bools. Any ideas?

PS: I would also like to use another date field as a fallback if the first one is null, and again the document to be weighted lowest if they both are null. But the main question is the one above.
