# Search-ui suggestions from different engine best practice

**URL:** <https://discuss.elastic.co/t/search-ui-suggestions-from-different-engine-best-practice/281468>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [August 15, 2021, 1:50am UTC](https://discuss.elastic.co/t/search-ui-suggestions-from-different-engine-best-practice/281468 "2021-08-15T01:50:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Llermaly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_llermaly/32/92019_2.png) [@Gustavo\_Llermaly](https://discuss.elastic.co/u/Gustavo_Llermaly)\
**Post date:** [August 15, 2021, 1:50am UTC](https://discuss.elastic.co/t/search-ui-suggestions-from-different-engine-best-practice/281468/1 "2021-08-15T01:50:59Z")

</div>

Hello,

I'm using search-ui and I was provided with a list of suggestions I have to add to the autocomplete.

I want to know what's the best way to implement it on the search-ui app.

I have this ideas:

1. Ingest suggestions in the same engine that documents and set different document\_types, then apply global filters to remove suggestions from search results and vice-versa

2. Create a new engine, then use the onSearch middleware to do a raw call to Appsearch to get the suggestions

3. Use a meta index to group both docs and suggestions engines, then use the approach #1

I dont like #1 because searches outside search-ui will be mixed.  
I dont like #2 because I dont feel good connecting to appsearch outside the original connector  
I dont like #3 because I understand meta-engines are supposed to group engines of the same type(?)

I post to hear from you what's the best option, maybe I missed something from the search-ui documentation.

Thanks

---

<div class="post-metadata">

**Author:** ![Gustavo\_Llermaly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_llermaly/32/92019_2.png) [@Gustavo\_Llermaly](https://discuss.elastic.co/u/Gustavo_Llermaly)\
**Post date:** [August 19, 2021, 5:39am UTC](https://discuss.elastic.co/t/search-ui-suggestions-from-different-engine-best-practice/281468/2 "2021-08-19T05:39:28Z")

</div>

I ended up following #2 , both 1 and 3 means I'm hitting the whole index for suggestions and I dont think is the best.

Added this to my AppSearch config after importing the javascript appsearch connector and created the client.

> **[GitHub - elastic/app-search-javascript: Elastic App Search Official...](https://github.com/elastic/app-search-javascript)**
>
> Elastic App Search Official JavaScript Client . Contribute to elastic/app-search-javascript development by creating an account on GitHub.

```auto
  onAutocomplete: async ({ searchTerm }) => {
    const opts = {
      search_fields: { suggestion: {} },
      result_fields: { suggestion: { raw: {} } },
    };
    const suggestions = await appSearchClient.search(searchTerm, opts);
    return {
      autocompletedResults: suggestions.results,
    };
  },

```

---

<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:** [September 16, 2021, 5:39am UTC](https://discuss.elastic.co/t/search-ui-suggestions-from-different-engine-best-practice/281468/3 "2021-09-16T05:39:36Z")

</div>

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