# Search terms matching order of precedence?

**URL:** <https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414>\
**Category:** Elasticsearch\
**Created:** [August 22, 2014, 5:47pm UTC](https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414 "2014-08-22T17:47:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Greene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_greene/32/1312_2.png) [@Eric\_Greene](https://discuss.elastic.co/u/Eric_Greene)\
**Post date:** [August 22, 2014, 5:47pm UTC](https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414/1 "2014-08-22T17:47:19Z")

</div>

Hi everyone, I would like to take a search query with multiple terms and  
possibly define an order of precedence in the following way.

(bare with me as I become familiar with elasticsearch lingo!)

Can I specify that the exact match is first (The search words "word A word  
B" matches "word A + word B"),  
then it matches "word B + word A",  
then just "word B" is found,  
then either "word A or word B"

I'd like to understand how to shuffle the above variations as well?

Thanks much.

--  
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/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 22, 2014, 5:50pm UTC](https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414/2 "2014-08-22T17:50:33Z")

</div>

Hello Eric ,

Please explore phrase query -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Also there is query\_string type which has support for AND , OR etc and even  
phrase query -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Hope that helps.

Thanks  
Vineeth

On Fri, Aug 22, 2014 at 11:17 PM, Eric Greene [ericdgreene@gmail.com](mailto:ericdgreene@gmail.com) wrote:

> Hi everyone, I would like to take a search query with multiple terms and  
> possibly define an order of precedence in the following way.
> 
> (bare with me as I become familiar with elasticsearch lingo!)
> 
> Can I specify that the exact match is first (The search words "word A word  
> B" matches "word A + word B"),  
> then it matches "word B + word A",  
> then just "word B" is found,  
> then either "word A or word B"
> 
> I'd like to understand how to shuffle the above variations as well?
> 
> Thanks much.
> 
> --  
> 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/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5mGsXg5q1u26aVRcXSn\_sUom2R25koZ23HLvVOMEcQSbQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mGsXg5q1u26aVRcXSn_sUom2R25koZ23HLvVOMEcQSbQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Eric\_Greene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_greene/32/1312_2.png) [@Eric\_Greene](https://discuss.elastic.co/u/Eric_Greene)\
**Post date:** [August 22, 2014, 6:07pm UTC](https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414/3 "2014-08-22T18:07:50Z")

</div>

Hi Vineeth thanks so much this looks like it will help me.

I have another question, if you don't mind... (or should I post a new  
question?)

I would like to specify my top results based on:

1. A description field and tags both are hits.
2. Description field only is a hit.
3. Tags only have a hit.

Is there something I can learn about to understand this? Thanks Eric

On Friday, August 22, 2014 10:50:48 AM UTC-7, vineeth mohan wrote:

> Hello Eric ,
> 
> Please explore phrase query -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#_phrase)
> 
> Also there is query\_string type which has support for AND , OR etc and  
> even phrase query -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-dsl-query-string-query)
> 
> Hope that helps.
> 
> Thanks  
> Vineeth
> 
> On Fri, Aug 22, 2014 at 11:17 PM, Eric Greene \<[ericd...@gmail.com](mailto:ericd...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi everyone, I would like to take a search query with multiple terms and  
> > possibly define an order of precedence in the following way.
> > 
> > (bare with me as I become familiar with elasticsearch lingo!)
> > 
> > Can I specify that the exact match is first (The search words "word A  
> > word B" matches "word A + word B"),  
> > then it matches "word B + word A",  
> > then just "word B" is found,  
> > then either "word A or word B"
> > 
> > I'd like to understand how to shuffle the above variations as well?
> > 
> > Thanks much.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/c3614746-8aa8-43d6-bda6-00787bc8abfa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c3614746-8aa8-43d6-bda6-00787bc8abfa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 22, 2014, 6:25pm UTC](https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414/4 "2014-08-22T18:25:55Z")

</div>

Hello Eric ,

I don't exactly understand your requirement.  
Please be elaborate.

Thanks  
Vineeth

On Fri, Aug 22, 2014 at 11:37 PM, Eric Greene [ericdgreene@gmail.com](mailto:ericdgreene@gmail.com) wrote:

> Hi Vineeth thanks so much this looks like it will help me.
> 
> I have another question, if you don't mind... (or should I post a new  
> question?)
> 
> I would like to specify my top results based on:
> 
> 1. A description field and tags both are hits.
> 2. Description field only is a hit.
> 3. Tags only have a hit.
> 
> Is there something I can learn about to understand this? Thanks Eric
> 
> On Friday, August 22, 2014 10:50:48 AM UTC-7, vineeth mohan wrote:
> 
> > Hello Eric ,
> > 
> > Please explore phrase query - [http://www.elasticsearch](http://www.elasticsearch).  
> > org/guide/en/elasticsearch/reference/current/query-dsl-  
> > match-query.html#\_phrase
> > 
> > Also there is query\_string type which has support for AND , OR etc and  
> > even phrase query - [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/query-dsl-query-string-query.html#query-  
> > dsl-query-string-query
> > 
> > Hope that helps.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Fri, Aug 22, 2014 at 11:17 PM, Eric Greene [ericd...@gmail.com](mailto:ericd...@gmail.com) wrote:
> > 
> > > Hi everyone, I would like to take a search query with multiple terms and  
> > > possibly define an order of precedence in the following way.
> > > 
> > > (bare with me as I become familiar with elasticsearch lingo!)
> > > 
> > > Can I specify that the exact match is first (The search words "word A  
> > > word B" matches "word A + word B"),  
> > > then it matches "word B + word A",  
> > > then just "word B" is found,  
> > > then either "word A or word B"
> > > 
> > > I'd like to understand how to shuffle the above variations as well?
> > > 
> > > Thanks much.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/405bb3f0-d496-4c3d-8aa8-ec7afaf2075f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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/c3614746-8aa8-43d6-bda6-00787bc8abfa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c3614746-8aa8-43d6-bda6-00787bc8abfa%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c3614746-8aa8-43d6-bda6-00787bc8abfa%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c3614746-8aa8-43d6-bda6-00787bc8abfa%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5mTEe8pR45vfOqU0DFUCsY68o0Sx3-SCWNKdfWaft6Fvg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mTEe8pR45vfOqU0DFUCsY68o0Sx3-SCWNKdfWaft6Fvg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:06am UTC](https://discuss.elastic.co/t/search-terms-matching-order-of-precedence/19414/5 "2017-07-06T01:06:55Z")

</div>


