# Preserving Position while searching

**URL:** <https://discuss.elastic.co/t/preserving-position-while-searching/17703>\
**Category:** Elasticsearch\
**Created:** [May 24, 2014, 8:04am UTC](https://discuss.elastic.co/t/preserving-position-while-searching/17703 "2014-05-24T08:04:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radhiks\_H\_S](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@Radhiks\_H\_S](https://discuss.elastic.co/u/Radhiks_H_S)\
**Post date:** [May 24, 2014, 8:04am UTC](https://discuss.elastic.co/t/preserving-position-while-searching/17703/1 "2014-05-24T08:04:15Z")

</div>

I need to make elasticsearch query to work with multiple words. I am using edgeNgram tokenizer to support autocompletion feature and I am using query\_string for searching.

DOCUMENTS

{  
"title":"Gold digital cinema",  
"region":"MUMBAI"  
}  
{  
"title":"cine park",  
"region":"MUMBAI"  
}  
{  
"title":"Premier Gold",  
"region":"MUMBAI"  
}

QUERY  
{  
"query": {  
"bool": {  
"should": [  
{  
"query\_string": {  
"fields": [  
"title.default\_title^10",  
"title.ngrams\_front^2"  
],  
"query": "gold cine",  
"boost": 2  
}  
},  
{  
"fuzzy": {  
"title.default\_title": {  
"value": "gold cine",  
"min\_similarity": 0.5,  
"max\_expansions": 50,  
"prefix\_length": 0  
}  
}  
},  
{  
"query\_string": {  
"fields": [  
"region"  
],  
"query": "MUMBAI"  
}  
}  
]  
}  
}  
}  
When I search for gold cine, I need "title":"Gold digital cinema" to be in the top results. But I am getting "title":"cine park" and "title":"Premier Gold" in top.

Is there any way to preserve position while searching? Thanks in advance.

--  
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/bddde391-125d-40ea-8e4b-0b34fbf087d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bddde391-125d-40ea-8e4b-0b34fbf087d4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 24, 2014, 2:12pm UTC](https://discuss.elastic.co/t/preserving-position-while-searching/17703/2 "2014-05-24T14:12:58Z")

</div>

You have options:

1. Use a match phrase query instead of a query string query.
2. Use the keyword tokenizer with an edge ngram token fitler on index and  
just use the keyword tokenizer on query.
3. Add the match phrase query as another should clause and give it a boost  
of 10 or something.

Each of these will produce different results so play with them.

I should also point out that exposing query\_string to users without  
escaping can give them the power to dump tons of load on Elasticsearch.  
The match query type is typically a better choice. Typically.

Nik

On Sat, May 24, 2014 at 10:04 AM, Radhiks H.S. [radhika.s@bookmyshow.com](mailto:radhika.s@bookmyshow.com)wrote:

> I need to make elasticsearch query to work with multiple words. I am using  
> edgeNgram tokenizer to support autocompletion feature and I am using  
> query\_string for searching.
> 
> DOCUMENTS
> 
> {  
> "title":"Gold digital cinema",  
> "region":"MUMBAI"  
> }  
> {  
> "title":"cine park",  
> "region":"MUMBAI"  
> }  
> {  
> "title":"Premier Gold",  
> "region":"MUMBAI"  
> }
> 
> QUERY  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "query\_string": {  
> "fields": [  
> "title.default\_title^10",  
> "title.ngrams\_front^2"  
> ],  
> "query": "gold cine",  
> "boost": 2  
> }  
> },  
> {  
> "fuzzy": {  
> "title.default\_title": {  
> "value": "gold cine",  
> "min\_similarity": 0.5,  
> "max\_expansions": 50,  
> "prefix\_length": 0  
> }  
> }  
> },  
> {  
> "query\_string": {  
> "fields": [  
> "region"  
> ],  
> "query": "MUMBAI"  
> }  
> }  
> ]  
> }  
> }  
> }  
> When I search for gold cine, I need "title":"Gold digital cinema" to be in  
> the top results. But I am getting "title":"cine park" and "title":"Premier  
> Gold" in top.
> 
> Is there any way to preserve position while searching? Thanks in advance.
> 
> --  
> 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/bddde391-125d-40ea-8e4b-0b34fbf087d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bddde391-125d-40ea-8e4b-0b34fbf087d4%40googlegroups.com)  
> .  
> 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/CAPmjWd0n913XSsXgPXJd8j0ckN2rfUmgCWtBH\_XhBpFuActW6w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0n913XSsXgPXJd8j0ckN2rfUmgCWtBH_XhBpFuActW6w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Radhiks\_H\_S](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@Radhiks\_H\_S](https://discuss.elastic.co/u/Radhiks_H_S)\
**Post date:** [May 26, 2014, 9:07am UTC](https://discuss.elastic.co/t/preserving-position-while-searching/17703/3 "2014-05-26T09:07:09Z")

</div>

Thank you Nikolas for your valuable information..I'll try it out..

--  
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/f8b4ab83-f1ed-4564-980e-ae37cf94f7c8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f8b4ab83-f1ed-4564-980e-ae37cf94f7c8%40googlegroups.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:26am UTC](https://discuss.elastic.co/t/preserving-position-while-searching/17703/4 "2017-07-06T01:26:58Z")

</div>


