# How to do Source Filtering for Suggestions in JS client

**URL:** <https://discuss.elastic.co/t/how-to-do-source-filtering-for-suggestions-in-js-client/70484>\
**Category:** Elasticsearch\
**Created:** [January 3, 2017, 9:49pm UTC](https://discuss.elastic.co/t/how-to-do-source-filtering-for-suggestions-in-js-client/70484 "2017-01-03T21:49:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsccheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gsccheng/32/13904_2.png) [@gsccheng](https://discuss.elastic.co/u/gsccheng)\
**Post date:** [January 3, 2017, 9:49pm UTC](https://discuss.elastic.co/t/how-to-do-source-filtering-for-suggestions-in-js-client/70484/1 "2017-01-03T21:49:24Z")

</div>

Hi, as explained in the [latest docs](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-suggesters-completion.html), source filtering can be performed. However, I couldn't figure out how to do this using the [JS API](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-suggest) for completion suggestions. Is this supported?

Right now my working query without the filtering is constructed like this:

```auto
es.suggest({
    index: 'my index name',
    body: {
      mySuggest: {
        prefix: 'some prefix',
        completion: {
          field: "suggest"
        }
      }
    }
  })

```

Thanks.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [January 5, 2017, 10:08am UTC](https://discuss.elastic.co/t/how-to-do-source-filtering-for-suggestions-in-js-client/70484/2 "2017-01-05T10:08:12Z")

</div>

Hi @gsccheng,

the Elasticsearch docs also state:

> Note that the \_suggest endpoint doesn’t support source filtering but using suggest on the \_search endpoint does.

So you need to call `es.search()` instead of `es.suggest()`. Something along those lines should do the trick (not tested):

```auto
es.search({
    index: 'my index name',
    _source: 'suggest',
    size: 0,
    body: {
      suggest: {
        mySuggest: {
          prefix: 'some prefix',
          completion: {
            field: "suggest"
          }
        }
      }
    }
  })

```

Daniel

---

<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 2, 2017, 10:08am UTC](https://discuss.elastic.co/t/how-to-do-source-filtering-for-suggestions-in-js-client/70484/3 "2017-02-02T10:08:31Z")

</div>

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