# How to add filter in "query suggestion" feature

**URL:** <https://discuss.elastic.co/t/how-to-add-filter-in-query-suggestion-feature/216112>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [January 22, 2020, 5:39pm UTC](https://discuss.elastic.co/t/how-to-add-filter-in-query-suggestion-feature/216112 "2020-01-22T17:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![viphuangwei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/viphuangwei/32/59306_2.png) [@viphuangwei](https://discuss.elastic.co/u/viphuangwei)\
**Post date:** [January 22, 2020, 5:39pm UTC](https://discuss.elastic.co/t/how-to-add-filter-in-query-suggestion-feature/216112/1 "2020-01-22T17:39:49Z")

</div>

Hi There,

Is that possible to add additional filters in the "query suggestion".  
e.g. There is an index:  
{  
jobID: string,  
jobTitle: string,  
_user_: string,  
.........  
}  
We select "jobTitle" this field as a suggestion field. One issue is that if we type words in the search box, then the auto-complete will return all the candidate words for all user.  
We would like to an additional filter to narrow down the candidate words belong to specific uers. like user = 'david'

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [January 23, 2020, 11:44am UTC](https://discuss.elastic.co/t/how-to-add-filter-in-query-suggestion-feature/216112/2 "2020-01-23T11:44:09Z")

</div>

Hi @viphuangwei. I don't believe it's possible to filter on the [Query Suggestion](https://swiftype.com/documentation/app-search/api/query-suggestion) endpoint.

However, I think you could implement something similar using the Search endpoint. You could limit [Search Field](https://swiftype.com/documentation/app-search/api/search/search-fields) to `jobTitle`. This would allow you to also apply a [Filter](https://swiftype.com/documentation/app-search/api/search/filters) on the `user` field.

```auto
{
  "query": "",
  "search_fields": {
    "jobTitle": {}
  },
  "result_fields": {
    "jobTitle": {
      "raw": {}
    }
  },
  "filters": {
    "user": "John"
  }
}

```

Does that make sense?

---

<div class="post-metadata">

**Author:** ![viphuangwei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/viphuangwei/32/59306_2.png) [@viphuangwei](https://discuss.elastic.co/u/viphuangwei)\
**Post date:** [January 23, 2020, 8:50pm UTC](https://discuss.elastic.co/t/how-to-add-filter-in-query-suggestion-feature/216112/3 "2020-01-23T20:50:07Z")

</div>

That's a work around solution. Thank you.

---

<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:** [February 20, 2020, 8:50pm UTC](https://discuss.elastic.co/t/how-to-add-filter-in-query-suggestion-feature/216112/4 "2020-02-20T20:50:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
