Query Suggestions Index - add default attribute

We are using an encoded filter in our keys to hide all products without a published=true flag in the storefront. This way we can push our unpublished products to the index without worrying about leaking them somehow.

Now we look into using the Query Suggestions Index. Problem is that with the key we can’t get any result from the index, because it is missing the published=true part. The response is always empty.

We would like to use the same key to access both indexes. Is it possible to add a fixed attribute to the query suggestions index or do you have a different workaround for me?

Thanks
Andi

It makes sense as a solution, but I’m not sure if it will be possible to inject attributes into the generated query suggestion index. I’ve reached out to the API team.

For now, you may need a separately scoped API key for suggestions.

Heya! I’ve confirmed you cannot add the published attribute to the Query Suggestions index, but there is a way to get an equivalent attribute surfaced in the generated index. It takes a few steps though:

  1. Add the published attribute to your Query Suggestions categories and put the number of possible values for published (2 if only true and false ) in “Show top”

  2. Each record in the Query Suggestions index will have a new field with the name of the source index and the following content: your-index-name { facets: { exact_matches: { published: [{ value: trueorfalsevalue, count: xx }] } } }

  3. Add your-index-name.facets.exact_matches.published to the attributes for faceting on your Query Suggestions index.

  4. Finally, modify your secured API key with the following filter published:true OR nameoftheirindex.facets.exact_matches.published:true

This will allow your users to search through both indices with one key with the added benefit of only retrieving query suggestions that match products that have the published:true attribute.