# How to use completion-suggester for city-location suggests respecting zip-codes

**URL:** <https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012>\
**Category:** Elasticsearch\
**Created:** [October 18, 2013, 10:44am UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012 "2013-10-18T10:44:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thorsten\_3](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@Thorsten\_3](https://discuss.elastic.co/u/Thorsten_3)\
**Post date:** [October 18, 2013, 10:44am UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/1 "2013-10-18T10:44:18Z")

</div>

Dear ElasticSearchers,  
I'm trying to get the new completion suggester to help me suggesting my  
users locations (cities).

My data mapping and data looks like this.[https://gist.github.com/ThorstenS/7039670](https://gist.github.com/ThorstenS/7039670)

What I want is that the names of the cities can be misspelled, and the user  
still gets some (hopefully correct) results.  
On the other hand, if the user searches via zip-code, the fuzziness should  
not be applied to the zip-code, but only to the name of the city.

In my example data above, if i'd search for  
curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
"city-suggest" : {  
"text" : "12345 Ci",  
"completion" : {  
"field" : "suggest",  
"fuzzy" : {  
"edit\_distance" : 2  
}  
}  
}  
}'

I'd get 2 results, but since I entered a valid zip-code, I'd only like to  
get the one result with that exact zip-code. But still maintain fuzziness  
on the name of the city.

I do understand that ElasticSearch's behavior totally makes sense, since  
I've requested the data with a fuzzy span.  
But is there a way to reach my goal?

Thanks for your help 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 18, 2013, 7:09pm UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/2 "2013-10-18T19:09:37Z")

</div>

try using the "prefix\_length" parameter and set it to the length of you  
zipcode then the fuzziness will not be applied to that prefix

simon

On Friday, October 18, 2013 12:44:18 PM UTC+2, Thorsten wrote:

> Dear ElasticSearchers,  
> I'm trying to get the new completion suggester to help me suggesting my  
> users locations (cities).
> 
> My data mapping and data looks like this.[https://gist.github.com/ThorstenS/7039670](https://gist.github.com/ThorstenS/7039670)
> 
> What I want is that the names of the cities can be misspelled, and the  
> user still gets some (hopefully correct) results.  
> On the other hand, if the user searches via zip-code, the fuzziness should  
> not be applied to the zip-code, but only to the name of the city.
> 
> In my example data above, if i'd search for  
> curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
> "city-suggest" : {  
> "text" : "12345 Ci",  
> "completion" : {  
> "field" : "suggest",  
> "fuzzy" : {  
> "edit\_distance" : 2  
> }  
> }  
> }  
> }'
> 
> I'd get 2 results, but since I entered a valid zip-code, I'd only like to  
> get the one result with that exact zip-code. But still maintain fuzziness  
> on the name of the city.
> 
> I do understand that Elasticsearch's behavior totally makes sense, since  
> I've requested the data with a fuzzy span.  
> But is there a way to reach my goal?
> 
> Thanks for your help 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thorsten\_3](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@Thorsten\_3](https://discuss.elastic.co/u/Thorsten_3)\
**Post date:** [October 19, 2013, 9:11am UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/3 "2013-10-19T09:11:58Z")

</div>

Thank you, that does the trick!

Any chance to increase the number of returned results?  
At the moment, I only get a maximum of 5 suggestions, although there are  
more locations in the index that should match the query.

Thanks

Thorsten

Am Freitag, 18. Oktober 2013 21:09:37 UTC+2 schrieb simonw:

> try using the "prefix\_length" parameter and set it to the length of you  
> zipcode then the fuzziness will not be applied to that prefix
> 
> simon
> 
> On Friday, October 18, 2013 12:44:18 PM UTC+2, Thorsten wrote:
> 
> > Dear ElasticSearchers,  
> > I'm trying to get the new completion suggester to help me suggesting my  
> > users locations (cities).
> > 
> > My data mapping and data looks like this.[https://gist.github.com/ThorstenS/7039670](https://gist.github.com/ThorstenS/7039670)
> > 
> > What I want is that the names of the cities can be misspelled, and the  
> > user still gets some (hopefully correct) results.  
> > On the other hand, if the user searches via zip-code, the fuzziness  
> > should not be applied to the zip-code, but only to the name of the city.
> > 
> > In my example data above, if i'd search for  
> > curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
> > "city-suggest" : {  
> > "text" : "12345 Ci",  
> > "completion" : {  
> > "field" : "suggest",  
> > "fuzzy" : {  
> > "edit\_distance" : 2  
> > }  
> > }  
> > }  
> > }'
> > 
> > I'd get 2 results, but since I entered a valid zip-code, I'd only like to  
> > get the one result with that exact zip-code. But still maintain fuzziness  
> > on the name of the city.
> > 
> > I do understand that Elasticsearch's behavior totally makes sense, since  
> > I've requested the data with a fuzzy span.  
> > But is there a way to reach my goal?
> > 
> > Thanks for your help 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 19, 2013, 6:17pm UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/4 "2013-10-19T18:17:57Z")

</div>

"size" : X should work just fine no?

simon

On Saturday, October 19, 2013 11:11:58 AM UTC+2, Thorsten wrote:

> Thank you, that does the trick!
> 
> Any chance to increase the number of returned results?  
> At the moment, I only get a maximum of 5 suggestions, although there are  
> more locations in the index that should match the query.
> 
> Thanks
> 
> Thorsten
> 
> Am Freitag, 18. Oktober 2013 21:09:37 UTC+2 schrieb simonw:
> 
> > try using the "prefix\_length" parameter and set it to the length of you  
> > zipcode then the fuzziness will not be applied to that prefix
> > 
> > simon
> > 
> > On Friday, October 18, 2013 12:44:18 PM UTC+2, Thorsten wrote:
> > 
> > > Dear ElasticSearchers,  
> > > I'm trying to get the new completion suggester to help me suggesting my  
> > > users locations (cities).
> > > 
> > > My data mapping and data looks like this.[https://gist.github.com/ThorstenS/7039670](https://gist.github.com/ThorstenS/7039670)
> > > 
> > > What I want is that the names of the cities can be misspelled, and the  
> > > user still gets some (hopefully correct) results.  
> > > On the other hand, if the user searches via zip-code, the fuzziness  
> > > should not be applied to the zip-code, but only to the name of the city.
> > > 
> > > In my example data above, if i'd search for  
> > > curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
> > > "city-suggest" : {  
> > > "text" : "12345 Ci",  
> > > "completion" : {  
> > > "field" : "suggest",  
> > > "fuzzy" : {  
> > > "edit\_distance" : 2  
> > > }  
> > > }  
> > > }  
> > > }'
> > > 
> > > I'd get 2 results, but since I entered a valid zip-code, I'd only like  
> > > to get the one result with that exact zip-code. But still maintain  
> > > fuzziness on the name of the city.
> > > 
> > > I do understand that Elasticsearch's behavior totally makes sense, since  
> > > I've requested the data with a fuzzy span.  
> > > But is there a way to reach my goal?
> > > 
> > > Thanks for your help 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thorsten\_3](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@Thorsten\_3](https://discuss.elastic.co/u/Thorsten_3)\
**Post date:** [October 19, 2013, 7:01pm UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/5 "2013-10-19T19:01:38Z")

</div>

Thank you for being patient with me, I did give that a try before, but got  
an exception.  
Just had the parameter placed on the wrong spot...

All working fine now 🙂

curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
"city-suggest" : {  
"text" : "12345 City",  
"completion" : {  
"field" : "suggest",  
"size" : 20,  
"fuzzy" : {  
"edit\_distance" : 2,  
"prefix\_length" : 5  
}  
}  
}  
}'

Am Samstag, 19. Oktober 2013 20:17:57 UTC+2 schrieb simonw:

> "size" : X should work just fine no?
> 
> simon
> 
> On Saturday, October 19, 2013 11:11:58 AM UTC+2, Thorsten wrote:
> 
> > Thank you, that does the trick!
> > 
> > Any chance to increase the number of returned results?  
> > At the moment, I only get a maximum of 5 suggestions, although there are  
> > more locations in the index that should match the query.
> > 
> > Thanks
> > 
> > Thorsten
> > 
> > Am Freitag, 18. Oktober 2013 21:09:37 UTC+2 schrieb simonw:
> > 
> > > try using the "prefix\_length" parameter and set it to the length of you  
> > > zipcode then the fuzziness will not be applied to that prefix
> > > 
> > > simon
> > > 
> > > On Friday, October 18, 2013 12:44:18 PM UTC+2, Thorsten wrote:
> > > 
> > > > Dear ElasticSearchers,  
> > > > I'm trying to get the new completion suggester to help me suggesting my  
> > > > users locations (cities).
> > > > 
> > > > My data mapping and data looks like this.[https://gist.github.com/ThorstenS/7039670](https://gist.github.com/ThorstenS/7039670)
> > > > 
> > > > What I want is that the names of the cities can be misspelled, and the  
> > > > user still gets some (hopefully correct) results.  
> > > > On the other hand, if the user searches via zip-code, the fuzziness  
> > > > should not be applied to the zip-code, but only to the name of the city.
> > > > 
> > > > In my example data above, if i'd search for  
> > > > curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
> > > > "city-suggest" : {  
> > > > "text" : "12345 Ci",  
> > > > "completion" : {  
> > > > "field" : "suggest",  
> > > > "fuzzy" : {  
> > > > "edit\_distance" : 2  
> > > > }  
> > > > }  
> > > > }  
> > > > }'
> > > > 
> > > > I'd get 2 results, but since I entered a valid zip-code, I'd only like  
> > > > to get the one result with that exact zip-code. But still maintain  
> > > > fuzziness on the name of the city.
> > > > 
> > > > I do understand that Elasticsearch's behavior totally makes sense,  
> > > > since I've requested the data with a fuzzy span.  
> > > > But is there a way to reach my goal?
> > > > 
> > > > Thanks for your help 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 20, 2013, 8:01am UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/6 "2013-10-20T08:01:15Z")

</div>

good stuff!! We are also working on adding support for a geo location in  
the suggester that allows you to "pre-filter" based on where the users "is"  
or it's "view" / "BoundingBox" center is.

happy that is worked out

simon

On Saturday, October 19, 2013 9:01:38 PM UTC+2, Thorsten wrote:

> Thank you for being patient with me, I did give that a try before, but got  
> an exception.  
> Just had the parameter placed on the wrong spot...
> 
> All working fine now 🙂
> 
> curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
> "city-suggest" : {  
> "text" : "12345 City",  
> "completion" : {  
> "field" : "suggest",  
> "size" : 20,  
> "fuzzy" : {  
> "edit\_distance" : 2,  
> "prefix\_length" : 5  
> }  
> }  
> }  
> }'
> 
> Am Samstag, 19. Oktober 2013 20:17:57 UTC+2 schrieb simonw:
> 
> > "size" : X should work just fine no?
> > 
> > simon
> > 
> > On Saturday, October 19, 2013 11:11:58 AM UTC+2, Thorsten wrote:
> > 
> > > Thank you, that does the trick!
> > > 
> > > Any chance to increase the number of returned results?  
> > > At the moment, I only get a maximum of 5 suggestions, although there are  
> > > more locations in the index that should match the query.
> > > 
> > > Thanks
> > > 
> > > Thorsten
> > > 
> > > Am Freitag, 18. Oktober 2013 21:09:37 UTC+2 schrieb simonw:
> > > 
> > > > try using the "prefix\_length" parameter and set it to the length of you  
> > > > zipcode then the fuzziness will not be applied to that prefix
> > > > 
> > > > simon
> > > > 
> > > > On Friday, October 18, 2013 12:44:18 PM UTC+2, Thorsten wrote:
> > > > 
> > > > > Dear ElasticSearchers,  
> > > > > I'm trying to get the new completion suggester to help me suggesting  
> > > > > my users locations (cities).
> > > > > 
> > > > > My data mapping and data looks like this.[https://gist.github.com/ThorstenS/7039670](https://gist.github.com/ThorstenS/7039670)
> > > > > 
> > > > > What I want is that the names of the cities can be misspelled, and the  
> > > > > user still gets some (hopefully correct) results.  
> > > > > On the other hand, if the user searches via zip-code, the fuzziness  
> > > > > should not be applied to the zip-code, but only to the name of the city.
> > > > > 
> > > > > In my example data above, if i'd search for  
> > > > > curl -X POST 'localhost:9200/geodb/\_suggest?pretty' -d '{  
> > > > > "city-suggest" : {  
> > > > > "text" : "12345 Ci",  
> > > > > "completion" : {  
> > > > > "field" : "suggest",  
> > > > > "fuzzy" : {  
> > > > > "edit\_distance" : 2  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }'
> > > > > 
> > > > > I'd get 2 results, but since I entered a valid zip-code, I'd only like  
> > > > > to get the one result with that exact zip-code. But still maintain  
> > > > > fuzziness on the name of the city.
> > > > > 
> > > > > I do understand that Elasticsearch's behavior totally makes sense,  
> > > > > since I've requested the data with a fuzzy span.  
> > > > > But is there a way to reach my goal?
> > > > > 
> > > > > Thanks for your help 🙂

--  
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).  
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, 2:11am UTC](https://discuss.elastic.co/t/how-to-use-completion-suggester-for-city-location-suggests-respecting-zip-codes/14012/7 "2017-07-06T02:11:37Z")

</div>


