# Add an extra flag in ES query to check if a field exists

**URL:** https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892
**Category:** Elasticsearch
**Created:** [February 19, 2014, 10:14am UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892 "2014-02-19T10:14:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rubyprince](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@rubyprince](https://discuss.elastic.co/u/rubyprince)
#### Post date: [February 19, 2014, 10:14am UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892/1 "2014-02-19T10:14:35Z")

</div>

Hi all,

Please see  
this [http://stackoverflow.com/questions/21875375/add-an-extra-flag-in-es-query-to-check-if-a-field-exists](http://stackoverflow.com/questions/21875375/add-an-extra-flag-in-es-query-to-check-if-a-field-exists)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8b78d867-a1c6-4cc8-adf6-90e0f66612dd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8b78d867-a1c6-4cc8-adf6-90e0f66612dd%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)
#### Post date: [February 19, 2014, 2:51pm UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892/2 "2014-02-19T14:51:23Z")

</div>

I'd check that the field arranged\_retweets exists in your mapping. If it  
doesn't exist in the mapping, try to add it. After that, your query should  
start returning results regardless of whether the documents indexed have  
that field populated or not.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c3fde18e-6906-486d-b550-a3c99149978d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c3fde18e-6906-486d-b550-a3c99149978d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![rubyprince](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@rubyprince](https://discuss.elastic.co/u/rubyprince)
#### Post date: [February 19, 2014, 3:40pm UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892/3 "2014-02-19T15:40:03Z")

</div>

arranged\_retweets do exist in the mapping. I have updated the question  
([elasticsearch - Add an extra flag in ES query to check if a field exists - Stack Overflow](http://stackoverflow.com/questions/21875375/add-an-extra-flag-in-es-query-to-check-if-a-field-exists))  
with the mapping

On Wednesday, February 19, 2014 8:21:23 PM UTC+5:30, Binh Ly wrote:

> I'd check that the field arranged\_retweets exists in your mapping. If it  
> doesn't exist in the mapping, try to add it. After that, your query should  
> start returning results regardless of whether the documents indexed have  
> that field populated or not.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/46ef1343-a9fb-4d6d-a842-ce52dc42a059%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/46ef1343-a9fb-4d6d-a842-ce52dc42a059%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)
#### Post date: [February 19, 2014, 4:22pm UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892/4 "2014-02-19T16:22:54Z")

</div>

I see, looks like it's an object so you'd probably need to check down to  
the leaf level, like for example:

doc["arranged\_retweets.author\_gender"].isEmpty() ||  
doc["arranged\_retweets.author\_link"].isEmpty()

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8831fe76-253d-41f4-bb21-62a98f4e999c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8831fe76-253d-41f4-bb21-62a98f4e999c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![rubyprince](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@rubyprince](https://discuss.elastic.co/u/rubyprince)
#### Post date: [February 26, 2014, 9:31am UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892/5 "2014-02-26T09:31:14Z")

</div>

Hi, many thanks for the pointer. I didnt try the code you mentioned, but  
changed my code like this:

"script": "!doc['arranged\_retweets.author\_gender'].empty"

This worked for me. Thank you very much for your help.

On Wednesday, February 19, 2014 9:52:54 PM UTC+5:30, Binh Ly wrote:

> I see, looks like it's an object so you'd probably need to check down to  
> the leaf level, like for example:
> 
> doc["arranged\_retweets.author\_gender"].isEmpty() ||  
> doc["arranged\_retweets.author\_link"].isEmpty()

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c68ca04d-acf8-4cda-8638-d118a088d1c5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c68ca04d-acf8-4cda-8638-d118a088d1c5%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:47am UTC](https://discuss.elastic.co/t/add-an-extra-flag-in-es-query-to-check-if-a-field-exists/15892/6 "2017-07-06T01:47:17Z")

</div>


