# Exists query

**URL:** https://discuss.elastic.co/t/exists-query/9673
**Category:** Elasticsearch
**Created:** [November 12, 2012, 11:55am UTC](https://discuss.elastic.co/t/exists-query/9673 "2012-11-12T11:55:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MacTommy](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MacTommy](https://discuss.elastic.co/u/MacTommy)
#### Post date: [November 12, 2012, 11:55am UTC](https://discuss.elastic.co/t/exists-query/9673/1 "2012-11-12T11:55:02Z")

</div>

Dear all,

I am a complete newbie, so I am sorry if this is a trivial question.  
The question is: why does the 'exists' query (see below) not work??

I did do a search and read the documentation and I have the idea that I am overlooking something quite simple, but I just don't seem to see what it is...

What I do is this:

1. I make a new column in an existing index (where the type is 'article'):  
$ curl -XPUT [http://myElasticSearchUrl:9280/myIndex/article/\_mapping](http://myElasticSearchUrl:9280/myIndex/article/_mapping) -d '{  
"article" : {  
"properties" : {  
"myMFCol" : {  
"type": "multi\_field",  
"fields" : { "myField1" : { "type": "string",  
"index" : "analyzed"},  
"myField2" : { "type": "string",  
"index" : "analyzed"}  
}  
}  
}  
}  
}'

2. I add a document, with the new field  
$ curl -XPUT [http://myElasticSearchUrl:9280/myIndex/article/myMFId1](http://myElasticSearchUrl:9280/myIndex/article/myMFId1) -d '{  
"articleurl": "[http://www.blabla.nl](http://www.blabla.nl)",  
"text": "Bla bla"s bla bla",  
"myMFCol" : {"myField1": "Check value 1",  
"myField2" : "Check value 2" }  
}'

3. Check that it worked:  
$ curl -XGET [http://myElasticSearchUrl:9280/myIndex/article/myMFId1](http://myElasticSearchUrl:9280/myIndex/article/myMFId1)  
{"\_index":"myIndex","\_type":"article","\_id":"myMFId1","\_version":2,"exists":true, "\_source" : {  
"articleurl": "[http://www.blabla.nl](http://www.blabla.nl)",  
"text": "Bla bla"s bla bla",  
"myMFCol" : {"myField1": "Check value 1",  
"myField2" : "Check value 2" }  
}}

4. Then I tty to get all documents that have this field  
$ curl -XGET [http://myElasticSearchUrl:9280/myIndex/article/\_search](http://myElasticSearchUrl:9280/myIndex/article/_search) -d '{ "filter" : { "exists" : {"field" : "myMFCol" } }  
{"took":14,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

?!?  
So I would expect to get this 1 document here, but I get none.

Why not?

Any help appreciated!

Cheers,

Tom

---

<div class="post-metadata">

### Author: ![MacTommy](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MacTommy](https://discuss.elastic.co/u/MacTommy)
#### Post date: [November 14, 2012, 11:16am UTC](https://discuss.elastic.co/t/exists-query/9673/2 "2012-11-14T11:16:40Z")

</div>

Right, and to follow up on myself... I should have done more digging because the answer is here:

[http://elasticsearch-users.115913.n3.nabble.com/Exists-Filter-doesn-t-work-with-objects-td3932787.html](http://elasticsearch-users.115913.n3.nabble.com/Exists-Filter-doesn-t-work-with-objects-td3932787.html)

In short, it doesn't work because the field I was trying to find out for if it existed or not is an 'object'. Or well, something that is not indexed as such anyway.

So the solution would be to add an additional column to the document (a simple integer or string field) that indicates whether or not the other field exists.

Just in case anybody knows a more elegant way doing this, I would be delighted to hear about it!

---

<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:04am UTC](https://discuss.elastic.co/t/exists-query/9673/3 "2017-07-06T03:04:24Z")

</div>


