How to do Source Filtering for Suggestions in JS client


#1

Hi, as explained in the latest docs, source filtering can be performed. However, I couldn't figure out how to do this using the JS API for completion suggestions. Is this supported?

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

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

Thanks.


(Daniel Mitterdorfer) #2

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):

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

Daniel


(system) #3

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