# Limit Completion Suggestion Results Based on other fields

**URL:** https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980
**Category:** Elasticsearch
**Created:** [October 16, 2013, 11:57pm UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980 "2013-10-16T23:57:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Johny\_Lam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johny_lam/32/1487_2.png) [@Johny\_Lam](https://discuss.elastic.co/u/Johny_Lam)
#### Post date: [October 16, 2013, 11:57pm UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/1 "2013-10-16T23:57:29Z")

</div>

Is it possible to restrict the results returned by the completion suggester  
to only the documents where a certain field matches something?

For example, with the hotel index on  
[http://www.elasticsearch.org/blog/you-complete-me/](http://www.elasticsearch.org/blog/you-complete-me/), is it possible to only  
get suggestions for hotels where the city is a specific city?

Thanks,  
Johny Lam

--  
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: ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)
#### Post date: [October 17, 2013, 1:11pm UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/2 "2013-10-17T13:11:28Z")

</div>

Hi,  
since the completion suggester is based on an FST that is loaded into  
memory and kept up-to-date at index time, it is not possible to filter  
suggestions.  
What you would need to do in your case is to build a different FST per  
city, but whether that's doable or not depends on how many city you have in  
your system. What I'm saying is that you pretty much need to know in  
advance the possible filters that might be applied and build a proper data  
structure at index time.

One other thing that you might want to consider is adding a prefix that  
contains the name of the city to your suggestions (input).

Hope this helps  
Luca

On Thursday, October 17, 2013 1:57:29 AM UTC+2, Johny Lam wrote:

> Is it possible to restrict the results returned by the completion  
> suggester to only the documents where a certain field matches something?
> 
> For example, with the hotel index on  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/you-complete-me/), is it possible to  
> only get suggestions for hotels where the city is a specific city?
> 
> Thanks,  
> Johny Lam

--  
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:15pm UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/3 "2013-10-18T19:15:07Z")

</div>

FYI we are working on geo support for the suggester where you can  
pre-filter based on geo location, would this help your usecase?

simon

On Thursday, October 17, 2013 1:57:29 AM UTC+2, Johny Lam wrote:

> Is it possible to restrict the results returned by the completion  
> suggester to only the documents where a certain field matches something?
> 
> For example, with the hotel index on  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/you-complete-me/), is it possible to  
> only get suggestions for hotels where the city is a specific city?
> 
> Thanks,  
> Johny Lam

--  
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: ![Johny\_Lam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johny_lam/32/1487_2.png) [@Johny\_Lam](https://discuss.elastic.co/u/Johny_Lam)
#### Post date: [October 21, 2013, 11:11pm UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/4 "2013-10-21T23:11:56Z")

</div>

No, my use case doesn't involve geo location. Although now that you bring  
it up, what makes it possible to filter by geo location but not by some  
other field?

On Friday, October 18, 2013 12:15:07 PM UTC-7, simonw wrote:

> FYI we are working on geo support for the suggester where you can  
> pre-filter based on geo location, would this help your usecase?
> 
> simon
> 
> On Thursday, October 17, 2013 1:57:29 AM UTC+2, Johny Lam wrote:
> 
> > Is it possible to restrict the results returned by the completion  
> > suggester to only the documents where a certain field matches something?
> > 
> > For example, with the hotel index on  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/you-complete-me/), is it possible to  
> > only get suggestions for hotels where the city is a specific city?
> > 
> > Thanks,  
> > Johny Lam

--  
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: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [November 21, 2013, 1:19am UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/5 "2013-11-21T01:19:51Z")

</div>

hi Luca/Simon - I posted a similar question on this forum earlier. Just  
curious to know your recommendation on how we can filter the suggestions  
based on the criteria specified in the query filter?

-Amit.

On Mon, Oct 21, 2013 at 4:11 PM, Johny Lam [johny.lam@gmail.com](mailto:johny.lam@gmail.com) wrote:

> No, my use case doesn't involve geo location. Although now that you bring  
> it up, what makes it possible to filter by geo location but not by some  
> other field?
> 
> On Friday, October 18, 2013 12:15:07 PM UTC-7, simonw wrote:
> 
> > FYI we are working on geo support for the suggester where you can  
> > pre-filter based on geo location, would this help your usecase?
> > 
> > simon
> > 
> > On Thursday, October 17, 2013 1:57:29 AM UTC+2, Johny Lam wrote:
> > 
> > > Is it possible to restrict the results returned by the completion  
> > > suggester to only the documents where a certain field matches something?
> > > 
> > > For example, with the hotel index on [http://www.elasticsearch.org/](http://www.elasticsearch.org/)  
> > > blog/you-complete-me/, is it possible to only get suggestions for  
> > > hotels where the city is a specific city?
> > > 
> > > Thanks,  
> > > Johny Lam
> > 
> > --  
> > 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).

--  
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: ![zkidkid](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zkidkid](https://discuss.elastic.co/u/zkidkid)
#### Post date: [November 21, 2013, 2:45am UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/6 "2013-11-21T02:45:42Z")

</div>

I think you would use edgeNgram and using phrase prefix search to implement  
your completion with filter.  
As my understand, current version is not support you to do it.

On Wednesday, November 20, 2013 5:19:51 PM UTC-8, amit.soni wrote:

> hi Luca/Simon - I posted a similar question on this forum earlier. Just  
> curious to know your recommendation on how we can filter the suggestions  
> based on the criteria specified in the query filter?
> 
> -Amit.
> 
> On Mon, Oct 21, 2013 at 4:11 PM, Johny Lam \<[john...@gmail.com](mailto:john...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > No, my use case doesn't involve geo location. Although now that you bring  
> > it up, what makes it possible to filter by geo location but not by some  
> > other field?
> > 
> > On Friday, October 18, 2013 12:15:07 PM UTC-7, simonw wrote:
> > 
> > > FYI we are working on geo support for the suggester where you can  
> > > pre-filter based on geo location, would this help your usecase?
> > > 
> > > simon
> > > 
> > > On Thursday, October 17, 2013 1:57:29 AM UTC+2, Johny Lam wrote:
> > > 
> > > > Is it possible to restrict the results returned by the completion  
> > > > suggester to only the documents where a certain field matches something?
> > > > 
> > > > For example, with the hotel index on [http://www.elasticsearch.org/](http://www.elasticsearch.org/)  
> > > > blog/you-complete-me/, is it possible to only get suggestions for  
> > > > hotels where the city is a specific city?
> > > > 
> > > > Thanks,  
> > > > Johny Lam
> > > 
> > > --  
> > > 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:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_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).  
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:05am UTC](https://discuss.elastic.co/t/limit-completion-suggestion-results-based-on-other-fields/13980/7 "2017-07-06T02:05:49Z")

</div>


