# Filtered autocomplete (suggester)

**URL:** <https://discuss.elastic.co/t/filtered-autocomplete-suggester/15472>\
**Category:** Elasticsearch\
**Created:** [January 29, 2014, 12:18pm UTC](https://discuss.elastic.co/t/filtered-autocomplete-suggester/15472 "2014-01-29T12:18:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilija\_Subasic](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@Ilija\_Subasic](https://discuss.elastic.co/u/Ilija_Subasic)\
**Post date:** [January 29, 2014, 12:18pm UTC](https://discuss.elastic.co/t/filtered-autocomplete-suggester/15472/1 "2014-01-29T12:18:33Z")

</div>

Hi,  
I am trying to combine it with the query or a filter with suggester, so  
that suggestions are returned only for the hits. Is it possible to  
constraint autcomplete (or any suggester for that matter) to work on a  
subset of data. E.g. I've got some users with associated documents and I  
want to serve them document title suggestions but only for the documents  
they can access. I've tried:

{  
"filter" : {  
"term" : {  
"user\_id" : "test"  
}  
},  
"suggest" : {  
"title\_suggester" : {  
"text" : "r",  
"completion" : {  
"field" : "title\_suggest"  
}  
}  
}  
}

and it returns all documents for user "test, and all suggestions for all  
users. I was able to hack around it by introducing an extra user\_id as a  
prefix for every suggestions, but looking for a more principled way.  
Thanks!

--  
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/6589e91d-fcd4-49db-b8c7-317ee800a498%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6589e91d-fcd4-49db-b8c7-317ee800a498%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 3, 2014, 7:46am UTC](https://discuss.elastic.co/t/filtered-autocomplete-suggester/15472/2 "2014-02-03T07:46:59Z")

</div>

Hey,

the completion suggester does not execute a real search query as it uses  
different data structures. This also means, that it does not support  
filters. There are plans to support something like a context in order to  
have a lightweight filter, see

> <https://github.com/elastic/elasticsearch/issues/3959>
>
> The suggester API is a good choice to get simple suggestions. But these suggesti…ons may take additional informations into account. Typing in something like \`restaurant\` will result in restaurants all over the world. But in this case the geolocation of the request can be used to get better results, namely those which are close to point of the request. Another usecase could be a simple \`type\` or \`group\` information which allows the suggester to return results fitting this context.
> In general the suggester should be able to handle generic information and create result with this information taken into account.

This will allow you suggest only for products in a certain category or for  
restaurants around you (as it also has geo support).

--Alex

On Wed, Jan 29, 2014 at 1:18 PM, Ilija Subasic [subasic.ilija@gmail.com](mailto:subasic.ilija@gmail.com)wrote:

> Hi,  
> I am trying to combine it with the query or a filter with suggester, so  
> that suggestions are returned only for the hits. Is it possible to  
> constraint autcomplete (or any suggester for that matter) to work on a  
> subset of data. E.g. I've got some users with associated documents and I  
> want to serve them document title suggestions but only for the documents  
> they can access. I've tried:
> 
> {  
> "filter" : {  
> "term" : {  
> "user\_id" : "test"  
> }  
> },  
> "suggest" : {  
> "title\_suggester" : {  
> "text" : "r",  
> "completion" : {  
> "field" : "title\_suggest"  
> }  
> }  
> }  
> }
> 
> and it returns all documents for user "test, and all suggestions for all  
> users. I was able to hack around it by introducing an extra user\_id as a  
> prefix for every suggestions, but looking for a more principled way.  
> Thanks!
> 
> --  
> 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/6589e91d-fcd4-49db-b8c7-317ee800a498%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6589e91d-fcd4-49db-b8c7-317ee800a498%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_QnXhauX2MNDX%2BWtqhmBoEypY50om%2BpqrJVi3-QNPJBA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_QnXhauX2MNDX%2BWtqhmBoEypY50om%2BpqrJVi3-QNPJBA%40mail.gmail.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, 1:53am UTC](https://discuss.elastic.co/t/filtered-autocomplete-suggester/15472/3 "2017-07-06T01:53:18Z")

</div>


