# Applying filters to the completion suggestor

**URL:** <https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483>\
**Category:** Elasticsearch\
**Created:** [November 20, 2013, 8:52am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483 "2013-11-20T08:52:34Z")\
**Posts on this page:** 7\
**Page:** 1

<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 20, 2013, 8:52am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/1 "2013-11-20T08:52:34Z")

</div>

Hello everyone - We have a use case where we are trying to implement 'type  
ahead' functionality for data that exists for different customers. Hence  
the 'type ahead' will be specific to a user based on the data that the  
specific user.

What I am trying to understand is how I can apply filters to completion  
suggestor so that it returns suggestions only for the filter result?

Thanks much in advance!

-Amit.

--  
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 27, 2013, 3:55am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/2 "2013-11-27T03:55:27Z")

</div>

Hi Amit,  
As my understand, the completion base on FST which will process your inputs  
at index time. so you could do it after you get filter result.  
For your purpose, you could use phrase prefix and edgeNGram to implement  
this feature.

Regards.

On Wednesday, November 20, 2013 12:52:34 AM UTC-8, amit.soni wrote:

> Hello everyone - We have a use case where we are trying to implement 'type  
> ahead' functionality for data that exists for different customers. Hence  
> the 'type ahead' will be specific to a user based on the data that the  
> specific user.
> 
> What I am trying to understand is how I can apply filters to completion  
> suggestor so that it returns suggestions only for the filter result?
> 
> Thanks much in advance!
> 
> -Amit.

--  
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/5ad04dd1-60e1-42c1-b7ca-d397e6fb6156%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ad04dd1-60e1-42c1-b7ca-d397e6fb6156%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:** [November 27, 2013, 11:08am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/3 "2013-11-27T11:08:01Z")

</div>

Hey,

right now there is possibility to filter results for the completion  
suggester, because it is not executing a query like a normal search query  
(the data structures used are highly different in order to ensure  
performance). We are right now in the process of creating something similar  
like a filter by allowing to specify a suggester context, but this is still  
in the works (not even in master)

> <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.

> <https://github.com/elastic/elasticsearch/pull/4044>
>
> This commit extends the \`CompletionSuggester\` by context
> informations. In exampl…e such a context informations can
> be a simple string representing a category reducing the
> suggestions in order to this category.
> 
> Three base implementations of these context informations
> have been setup in this commit.
> \- a Category Context
> \- a Geo Context
> \- a Field Context
> 
> All the mapping for these context informations are
> specified within a context field in the completion
> field that should use this kind of information.
> \## Mapping Example
> 
> The following example shows the mapping for a GeoContext.
> 
> \`\`\`
> {
> "testType":{
> "properties":{
> "testField":{
> "type":"completion",
> "index\_analyzer":"simple",
> "search\_analyzer":"simple",
> "payloads":true,
> "preserve\_separators":false,
> "preserve\_position\_increments":true,
> "context":{
> "geo":{
> "separator":"|",
> "precision":8,
> "neighbors":true
> }
> }
> }
> }
> }
> }
> \`\`\`
> \## Indexing
> 
> During indexing a document the subfield \`context\` of the
> completion field contains the data to be used in order
> to provide suggestions.
> 
> \`\`\`
> {
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context":"u33dc1v0xupz"
> }
> }
> \`\`\`
> \## Suggestion Example
> 
> The Suggestion request is extended by a context value. The
> suggest request for a geolocation looks like
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context":{
> "geo":"u33dc0cpke4q"
> }
> }
> }
> }
> \`\`\`
> 
> The context objects contains a field with the same name as
> defined in the mapping. According to the type of the context
> this field contains the data associated with the suggestion
> request. In this example the geohash of a location.
> \## Category Context
> 
> The simplest way to use this feature is a category context. It
> supports a arbitrary name of a category to use with the completion
> suggest API.
> 
> To set the context support to the category type this option must be
> set to \`true\`:
> 
> \`\`\`
> "testField":{
> "type":"completion",
> "context":{
> "category": true
> }
> }
> \`\`\`
> 
> The name of the context category then needs to be set within the
> suggestion context during indexing:
> 
> \`\`\`
> {
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context":"delivery"
> }
> }
> \`\`\`
> 
> and can be used by setting the category value:
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context":{
> "category":"delivery"
> }
> }
> }
> }
> \`\`\`
> \## Field Context
> 
> The Field Context works like the category context but the value of this
> will context will not explicitly be set. It refers to another field in
> the document. In example a \`category\` field.
> 
> \`\`\`
> {
> "category":{
> "type": "string"
> },
> "testField":{
> "type":"completion",
> "context":{
> "field": "category"
> }
> }
> }
> \`\`\`
> 
> for indexing the field context must be set to true:
> 
> \`\`\`
> {
> "category":"delivery",
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context":true
> }
> }
> \`\`\`
> 
> and suggestions use the \`context.field\` value
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context": {
> "field": "delivery"
> }
> }
> }
> }
> \`\`\`
> \## Geo Context
> 
> The last context feature is the GeoContext. It take a location into account.
> For example if one searches for delivery services it might be use full to find
> results around the location the query was sent. This context internally works
> on geohashes only but the REST API allows any form defined for \`geo\_points\`
> 
> In the mapping this kind of context is configured by two parameters:
> \- precision
> \- neighbors
> 
> The \`precision\` option is used to configure the range of result. If the
> \`neighbors\` option is enabled not only the given geohash cell will be used
> but also all it's neighbors. 
> 
> \`\`\`
> "context":{
> "geo":{
> "separator":"|",
> "precision":8,
> "neighbors":true
> }
> }
> \`\`\`
> 
> The context during indexing is set to the location of the input:
> 
> \`\`\`
> {
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context": "u33dc1v0xupz"
> }
> }
> \`\`\`
> 
> To get a ist of suggestions around a specific area the \`context.geo\` field
> must contain the position of this area:
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context": {
> "geo": "u33dc0cpke4q"
> }
> }
> }
> }
> \`\`\`
> 
> Closes #3959

--Alex

On Wed, Nov 27, 2013 at 4:55 AM, kidkid [zkidkid@gmail.com](mailto:zkidkid@gmail.com) wrote:

> Hi Amit,  
> As my understand, the completion base on FST which will process your  
> inputs at index time. so you could do it after you get filter result.  
> For your purpose, you could use phrase prefix and edgeNGram to implement  
> this feature.
> 
> Regards.
> 
> On Wednesday, November 20, 2013 12:52:34 AM UTC-8, amit.soni wrote:
> 
> > Hello everyone - We have a use case where we are trying to implement  
> > 'type ahead' functionality for data that exists for different customers.  
> > Hence the 'type ahead' will be specific to a user based on the data that  
> > the specific user.
> > 
> > What I am trying to understand is how I can apply filters to completion  
> > suggestor so that it returns suggestions only for the filter result?
> > 
> > Thanks much in advance!
> > 
> > -Amit.
> 
> --  
> 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/5ad04dd1-60e1-42c1-b7ca-d397e6fb6156%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ad04dd1-60e1-42c1-b7ca-d397e6fb6156%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/CAGCwEM8CN8aHo84%2BBH3cNdsZZSV0OgLYiH9q6NuHLn3dSx42fA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8CN8aHo84%2BBH3cNdsZZSV0OgLYiH9q6NuHLn3dSx42fA%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:** ![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 27, 2013, 4:58pm UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/4 "2013-11-27T16:58:15Z")

</div>

Thanks Sang and Alex.

Nice to know this request is in the backlog, will wait for it to be out for  
use.

-Amit.

On Wed, Nov 27, 2013 at 3:08 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> right now there is possibility to filter results for the completion  
> suggester, because it is not executing a query like a normal search query  
> (the data structures used are highly different in order to ensure  
> performance). We are right now in the process of creating something similar  
> like a filter by allowing to specify a suggester context, but this is still  
> in the works (not even in master)
> 
> [Context extension of the Suggester · Issue #3959 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3959)  
> [https://github.com/elasticsearch/elasticsearch/pull/4044](https://github.com/elasticsearch/elasticsearch/pull/4044)
> 
> --Alex
> 
> On Wed, Nov 27, 2013 at 4:55 AM, kidkid [zkidkid@gmail.com](mailto:zkidkid@gmail.com) wrote:
> 
> > Hi Amit,  
> > As my understand, the completion base on FST which will process your  
> > inputs at index time. so you could do it after you get filter result.  
> > For your purpose, you could use phrase prefix and edgeNGram to implement  
> > this feature.
> > 
> > Regards.
> > 
> > On Wednesday, November 20, 2013 12:52:34 AM UTC-8, amit.soni wrote:
> > 
> > > Hello everyone - We have a use case where we are trying to implement  
> > > 'type ahead' functionality for data that exists for different customers.  
> > > Hence the 'type ahead' will be specific to a user based on the data that  
> > > the specific user.
> > > 
> > > What I am trying to understand is how I can apply filters to completion  
> > > suggestor so that it returns suggestions only for the filter result?
> > > 
> > > Thanks much in advance!
> > > 
> > > -Amit.
> > 
> > --  
> > 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/5ad04dd1-60e1-42c1-b7ca-d397e6fb6156%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ad04dd1-60e1-42c1-b7ca-d397e6fb6156%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/CAGCwEM8CN8aHo84%2BBH3cNdsZZSV0OgLYiH9q6NuHLn3dSx42fA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8CN8aHo84%2BBH3cNdsZZSV0OgLYiH9q6NuHLn3dSx42fA%40mail.gmail.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/CAAOGaQKdnR%3DVA2TLAX4fTn8A\_NZ1VJQQb%2BQv14Te8ghkUtSW\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQKdnR%3DVA2TLAX4fTn8A_NZ1VJQQb%2BQv14Te8ghkUtSW_w%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:** ![Andrea\_Salvadore](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrea_salvadore/32/1839_2.png) [@Andrea\_Salvadore](https://discuss.elastic.co/u/Andrea_Salvadore)\
**Post date:** [January 31, 2014, 9:17am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/5 "2014-01-31T09:17:27Z")

</div>

Hi  
is this feature likely to go into 1.0 release? We'd love to be able to use  
the completion filter

On Wednesday, 20 November 2013 08:52:34 UTC, amit.soni wrote:

> Hello everyone - We have a use case where we are trying to implement 'type  
> ahead' functionality for data that exists for different customers. Hence  
> the 'type ahead' will be specific to a user based on the data that the  
> specific user.
> 
> What I am trying to understand is how I can apply filters to completion  
> suggestor so that it returns suggestions only for the filter result?
> 
> Thanks much in advance!
> 
> -Amit.

--  
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/5816c3f7-7e24-4c38-8f23-3de4a8d8acb8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5816c3f7-7e24-4c38-8f23-3de4a8d8acb8%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:** ![rakesh\_goyal](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rakesh\_goyal](https://discuss.elastic.co/u/rakesh_goyal)\
**Post date:** [February 13, 2014, 11:39am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/6 "2014-02-13T11:39:41Z")

</div>

Is there any plan to release this feature in near future.

On Friday, 31 January 2014 14:47:27 UTC+5:30, Andrea Salvadore wrote:

> Hi  
> is this feature likely to go into 1.0 release? We'd love to be able to use  
> the completion filter
> 
> On Wednesday, 20 November 2013 08:52:34 UTC, amit.soni wrote:
> 
> > Hello everyone - We have a use case where we are trying to implement  
> > 'type ahead' functionality for data that exists for different customers.  
> > Hence the 'type ahead' will be specific to a user based on the data that  
> > the specific user.
> > 
> > What I am trying to understand is how I can apply filters to completion  
> > suggestor so that it returns suggestions only for the filter result?
> > 
> > Thanks much in advance!
> > 
> > -Amit.

--  
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/1cb5915e-e522-4932-b612-a8b97884eefa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1cb5915e-e522-4932-b612-a8b97884eefa%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:** ![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:50am UTC](https://discuss.elastic.co/t/applying-filters-to-the-completion-suggestor/14483/7 "2017-07-06T01:50:32Z")

</div>


