# Need to match all terms in query, but they can be in any document property

**URL:** <https://discuss.elastic.co/t/need-to-match-all-terms-in-query-but-they-can-be-in-any-document-property/7433>\
**Category:** Elasticsearch\
**Created:** [April 22, 2012, 6:37am UTC](https://discuss.elastic.co/t/need-to-match-all-terms-in-query-but-they-can-be-in-any-document-property/7433 "2012-04-22T06:37:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Schier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregory_schier/32/1259_2.png) [@Gregory\_Schier](https://discuss.elastic.co/u/Gregory_Schier)\
**Post date:** [April 22, 2012, 6:37am UTC](https://discuss.elastic.co/t/need-to-match-all-terms-in-query-but-they-can-be-in-any-document-property/7433/1 "2012-04-22T06:37:04Z")

</div>

Hello.

I have an index of menu items that I am trying to query on. A  
simplified representation is that an item has a name, a description,  
and an array of cuisines (basically tags).  
If someone searches for "baked goods" it is required that both "baked"  
and "goods" appear in the document, but "baked" could be in the name,  
and "goods" could be in the description. Also "baked goods" could also  
just be one of the item's cuisines. I was initially using a mlt query  
to do this but it doesn't seem to be returning as many results as it  
should (maybe my understanding of how it works is incorrect?). It  
seems to be returning all of the items where "baked" is in the  
description, and "baked goods" is one of it's cuisines (note that no  
items contain these terms in the "name" property). There are lots of  
items with "baked goods" as a cuisine that are not being returned.

my mlt query has the following properties:

- fields = ['cuisine', 'name', 'description']
- max\_query\_terms = 12
- min\_term\_freq = 1
- min\_doc\_freq = 1
- percent\_terms\_to\_match = 1

My feeling is that cuisines being an array of strings has something to  
do with it, but I really have no idea. Is there an easy way to make  
sure all query terms appear in a document, but not care which fields  
they are found in given a specific set of fields?

Hope I was clear enough in my explanation.

Thanks!

~Gregory

---

<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:** [April 25, 2012, 3:34pm UTC](https://discuss.elastic.co/t/need-to-match-all-terms-in-query-but-they-can-be-in-any-document-property/7433/2 "2012-04-25T15:34:35Z")

</div>

Maybe just use the \_all field htat gets created automatically by default,  
and query on it?

On Sun, Apr 22, 2012 at 9:37 AM, Gregory Schier [gschier1990@gmail.com](mailto:gschier1990@gmail.com)wrote:

> Hello.
> 
> I have an index of menu items that I am trying to query on. A  
> simplified representation is that an item has a name, a description,  
> and an array of cuisines (basically tags).  
> If someone searches for "baked goods" it is required that both "baked"  
> and "goods" appear in the document, but "baked" could be in the name,  
> and "goods" could be in the description. Also "baked goods" could also  
> just be one of the item's cuisines. I was initially using a mlt query  
> to do this but it doesn't seem to be returning as many results as it  
> should (maybe my understanding of how it works is incorrect?). It  
> seems to be returning all of the items where "baked" is in the  
> description, and "baked goods" is one of it's cuisines (note that no  
> items contain these terms in the "name" property). There are lots of  
> items with "baked goods" as a cuisine that are not being returned.
> 
> my mlt query has the following properties:
> 
> - fields = ['cuisine', 'name', 'description']
> - max\_query\_terms = 12
> - min\_term\_freq = 1
> - min\_doc\_freq = 1
> - percent\_terms\_to\_match = 1
> 
> My feeling is that cuisines being an array of strings has something to  
> do with it, but I really have no idea. Is there an easy way to make  
> sure all query terms appear in a document, but not care which fields  
> they are found in given a specific set of fields?
> 
> Hope I was clear enough in my explanation.
> 
> Thanks!
> 
> ~Gregory

---

<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:31am UTC](https://discuss.elastic.co/t/need-to-match-all-terms-in-query-but-they-can-be-in-any-document-property/7433/3 "2017-07-06T03:31:09Z")

</div>

Closed on July 6, 2017, 3:31am UTC


