# Expressing has-any-value in the Query DSL

**URL:** <https://discuss.elastic.co/t/expressing-has-any-value-in-the-query-dsl/2844>\
**Category:** Elasticsearch\
**Created:** [March 11, 2010, 10:46am UTC](https://discuss.elastic.co/t/expressing-has-any-value-in-the-query-dsl/2844 "2010-03-11T10:46:27Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [March 11, 2010, 10:46am UTC](https://discuss.elastic.co/t/expressing-has-any-value-in-the-query-dsl/2844/1 "2010-03-11T10:46:27Z")

</div>

Hiya

If I have a mapping that looks like this:

{  
"name": { "type": "string", "index": "analyzed"},  
.... more fields ...  
}

Is there any way of saying "give me only documents which have a value in  
the name field", ie name is not blank.

Would it be:

{  
"bool": {  
"mustNot": [{ "term": { "name": ""}}]  
}  
}

That doesn't seem to work.

Would I have to add a new field to the mapping? eg

{ "has\_name": { "type": "boolean" }}

thanks

Clint

--  
Web Announcements Limited is a company registered in England and Wales,  
with company number 05608868, with registered address at 10 Arvon Road,  
London, N5 1PR.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 11, 2010, 12:01pm UTC](https://discuss.elastic.co/t/expressing-has-any-value-in-the-query-dsl/2844/2 "2010-03-11T12:01:54Z")

</div>

You can pass a JSON null in the name field when it has no value, and add a  
nullValue to the name mapping, for example:

{  
"name": { "type": "string", "index": "analyzed", "nullValue":"na"},  
.... more fields ...  
}

Then, you can search on all the names that have "na".

-shay.banon

On Thu, Mar 11, 2010 at 12:46 PM, Clinton Gormley  
[clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)wrote:

> Hiya
> 
> If I have a mapping that looks like this:
> 
> {  
> "name": { "type": "string", "index": "analyzed"},  
> .... more fields ...  
> }
> 
> Is there any way of saying "give me only documents which have a value in  
> the name field", ie name is not blank.
> 
> Would it be:
> 
> {  
> "bool": {  
> "mustNot": [{ "term": { "name": ""}}]  
> }  
> }
> 
> That doesn't seem to work.
> 
> Would I have to add a new field to the mapping? eg
> 
> { "has\_name": { "type": "boolean" }}
> 
> thanks
> 
> Clint
> 
> --  
> Web Announcements Limited is a company registered in England and Wales,  
> with company number 05608868, with registered address at 10 Arvon Road,  
> London, N5 1PR.

---

<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:25am UTC](https://discuss.elastic.co/t/expressing-has-any-value-in-the-query-dsl/2844/3 "2017-07-06T04:25:20Z")

</div>

Closed on July 6, 2017, 4:25am UTC


