# Elasticsearch filtered completion suggester

**URL:** https://discuss.elastic.co/t/elasticsearch-filtered-completion-suggester/23638
**Category:** Elasticsearch
**Created:** [May 18, 2015, 6:06am UTC](https://discuss.elastic.co/t/elasticsearch-filtered-completion-suggester/23638 "2015-05-18T06:06:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![redserpent7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redserpent7/32/467_2.png) [@redserpent7](https://discuss.elastic.co/u/redserpent7)
#### Post date: [May 18, 2015, 6:06am UTC](https://discuss.elastic.co/t/elasticsearch-filtered-completion-suggester/23638/1 "2015-05-18T06:06:39Z")

</div>

Hi,

I am trying to add a filter to a completion suggester. My case is a s  
follows:

My index follows the user data flow pattern, but instead of users I have  
accounts. Each account has its own alias and can consist of multiple number  
of users that share the same document. Each document has an identification  
field that correspond to the user who indexed that document.

What I want is to find a way that when a user enters some text in the  
search box. The completion suggester will only return suggestions from  
documents that have that user's ID.

Lets assume this example:

curl -XPUT "[http://localhost:9200/account1/photos/\_mapping](http://localhost:9200/account1/photos/_mapping)" -d'  
{  
"photos": {  
"properties": {  
"userid": {  
"type": "long"  
},  
"name": {  
"type": "string"  
},  
"size": {  
"type": "long"  
},  
"createDate": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
"tags": {  
"type": "string"  
},  
"suggest": {  
"type": "completion",  
"index\_analyzer": "simple",  
"search\_analyzer": "simple",  
"payloads": false  
}  
}  
}  
}'

Now lets assume user 1 has indexed a photo:  
curl -XPUT "[http://localhost:9200/account1/photos/1](http://localhost:9200/account1/photos/1)" -d'  
{  
"userid": 1,  
"name": "somephoto.jpg",  
"size": 10000,  
"tags": [  
"paris",  
"noon"  
],  
"suggest": {  
"input": [  
"paris",  
"noon"  
]  
},  
"createDate": "2013-12-19"  
}'

Now user 2 has also indexed a new photo:

curl -XPUT "[http://localhost:9200/account1/photos/2](http://localhost:9200/account1/photos/2)" -d'  
{  
"userid": 2,  
"name": "somephoto.jpg",  
"size": 10000,  
"tags": [  
"london",  
"night"  
],  
"suggest": {  
"input": [  
"london",  
"night"  
]  
},  
"createDate": "2013-12-19"  
}'

Now what I want to do is when user 1 enters the text "lon" in the search  
box, the suggester will return _NO_ autocomplete suggestions. Yet when he  
enters the test "par" the suggester will return "paris".

Is there anyway to do this?

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Andre\_Carvalho](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andre_carvalho/32/706_2.png) [@Andre\_Carvalho](https://discuss.elastic.co/u/Andre_Carvalho)
#### Post date: [May 18, 2015, 1:09pm UTC](https://discuss.elastic.co/t/elasticsearch-filtered-completion-suggester/23638/2 "2015-05-18T13:09:56Z")

</div>

I think the suggester context is a good bet to your use case: (

> **[Context Suggester | Elasticsearch Guide \[1.5\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/1.5/suggester-context.html)**

).

# André Carvalho

+55 21 98739-1097 / [br.linkedin.com/in/andrestc/](http://br.linkedin.com/in/andrestc/)

2015-05-18 3:06 GMT-03:00 Zaid Amir [redserpent7@gmail.com](mailto:redserpent7@gmail.com):

> Hi,
> 
> I am trying to add a filter to a completion suggester. My case is a s  
> follows:
> 
> My index follows the user data flow pattern, but instead of users I have  
> accounts. Each account has its own alias and can consist of multiple number  
> of users that share the same document. Each document has an identification  
> field that correspond to the user who indexed that document.
> 
> What I want is to find a way that when a user enters some text in the  
> search box. The completion suggester will only return suggestions from  
> documents that have that user's ID.
> 
> Lets assume this example:
> 
> curl -XPUT "[http://localhost:9200/account1/photos/\_mapping](http://localhost:9200/account1/photos/_mapping)" -d'  
> {  
> "photos": {  
> "properties": {  
> "userid": {  
> "type": "long"  
> },  
> "name": {  
> "type": "string"  
> },  
> "size": {  
> "type": "long"  
> },  
> "createDate": {  
> "type": "date",  
> "format": "dateOptionalTime"  
> },  
> "tags": {  
> "type": "string"  
> },  
> "suggest": {  
> "type": "completion",  
> "index\_analyzer": "simple",  
> "search\_analyzer": "simple",  
> "payloads": false  
> }  
> }  
> }  
> }'
> 
> Now lets assume user 1 has indexed a photo:  
> curl -XPUT "[http://localhost:9200/account1/photos/1](http://localhost:9200/account1/photos/1)" -d'  
> {  
> "userid": 1,  
> "name": "somephoto.jpg",  
> "size": 10000,  
> "tags": [  
> "paris",  
> "noon"  
> ],  
> "suggest": {  
> "input": [  
> "paris",  
> "noon"  
> ]  
> },  
> "createDate": "2013-12-19"  
> }'
> 
> Now user 2 has also indexed a new photo:
> 
> curl -XPUT "[http://localhost:9200/account1/photos/2](http://localhost:9200/account1/photos/2)" -d'  
> {  
> "userid": 2,  
> "name": "somephoto.jpg",  
> "size": 10000,  
> "tags": [  
> "london",  
> "night"  
> ],  
> "suggest": {  
> "input": [  
> "london",  
> "night"  
> ]  
> },  
> "createDate": "2013-12-19"  
> }'
> 
> Now what I want to do is when user 1 enters the text "lon" in the search  
> box, the suggester will return _NO_ autocomplete suggestions. Yet when he  
> enters the test "par" the suggester will return "paris".
> 
> Is there anyway to do this?
> 
> ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> 
> 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/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/93b62d01-60cd-4d7c-a68d-ed7edb987122%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/CACigSzL0RK5Yd%3DH49y1amZ1ZFaQ8J002XOPGzJx%2B2Hts8CP1vg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CACigSzL0RK5Yd%3DH49y1amZ1ZFaQ8J002XOPGzJx%2B2Hts8CP1vg%40mail.gmail.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, 12:13am UTC](https://discuss.elastic.co/t/elasticsearch-filtered-completion-suggester/23638/3 "2017-07-06T00:13:31Z")

</div>


