# How not to query on specific fields in elasticsearch

**URL:** <https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193>\
**Category:** Elasticsearch\
**Created:** [February 23, 2017, 10:28am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193 "2017-02-23T10:28:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divya\_Bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bhardwaj/32/15231_2.png) [@Divya\_Bhardwaj](https://discuss.elastic.co/u/Divya_Bhardwaj)\
**Post date:** [February 23, 2017, 10:28am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/1 "2017-02-23T10:28:49Z")

</div>

My usecase demands to search on all fields for a given keyword except 2 fields. must\_not is not working, Pls guide.

Thanks

---

<div class="post-metadata">

**Author:** ![wenpos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wenpos/32/15326_2.png) [@wenpos](https://discuss.elastic.co/u/wenpos)\
**Post date:** [February 23, 2017, 10:49am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/2 "2017-02-23T10:49:00Z")

</div>

to set up parmeter 'include\_in\_all ' in mappings on the 2 fields, and use query\_string or simple\_query\_string query.  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.2/include-in-all.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/include-in-all.html)  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-simple-query-string-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-simple-query-string-query.html)

---

<div class="post-metadata">

**Author:** ![Divya\_Bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bhardwaj/32/15231_2.png) [@Divya\_Bhardwaj](https://discuss.elastic.co/u/Divya_Bhardwaj)\
**Post date:** [February 27, 2017, 7:16am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/3 "2017-02-27T07:16:51Z")

</div>

Thanks Wenpos for the reply. But I will need these 2 fields in other queries, so I cannot do an "include\_in\_all" to false, since it may bother my other queries. Pls let me know if there is a way out.

Thanks

---

<div class="post-metadata">

**Author:** ![wenpos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wenpos/32/15326_2.png) [@wenpos](https://discuss.elastic.co/u/wenpos)\
**Post date:** [March 2, 2017, 12:47am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/4 "2017-03-02T00:47:31Z")

</div>

The two fields can also be assigned in query DSL, no matter set it “include\_in\_all” or not. If you need not use \_all, you 'd better have specific fields.  
--Fanfan

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [March 2, 2017, 8:48am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/5 "2017-03-02T08:48:37Z")

</div>

> [@Divya\_Bhardwaj](#):
>
> must\_not is not working

Why the must\_not is not working ?

If you have a bool query with one must on all fields and one must\_not on both fields, it should be ok ?

---

<div class="post-metadata">

**Author:** ![Divya\_Bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bhardwaj/32/15231_2.png) [@Divya\_Bhardwaj](https://discuss.elastic.co/u/Divya_Bhardwaj)\
**Post date:** [March 3, 2017, 7:01am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/6 "2017-03-03T07:01:51Z")

</div>

I am not sure... may be loosing something while mapping

---

<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:** [March 31, 2017, 7:01am UTC](https://discuss.elastic.co/t/how-not-to-query-on-specific-fields-in-elasticsearch/76193/7 "2017-03-31T07:01:57Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
