Autocomplete: show selected option in the result component

Hello, I´m trying to implement the search-ui with an elasticsearch API, based on the example provided in the library I have managed to make everything works except for the Autocomplete.

I´m seeing the autocomplete options, and I can select them, and I register the clicks on them, but I can´t find a way to show the selected autocomplete option, in the results component.

This is my configuration:

    const config = {
      debug: true,
      hasA11yNotifications: true,
      onResultClick: () => {
        /* Not implemented */
      onAutocompleteResultClick: async ({ documentId, query, ...args }) => {
        /* Not implemented */
        let requestBody = buildSearchByIDQuery(documentId);
        const json = await runRequest(requestBody);
        let state = buildState(json);
        return state;
      onAutocomplete: async ({ searchTerm }) => { 
        const requestBody = buildRequest({ searchTerm });
        const json = await runRequest(requestBody);
        const state = buildState(json);
        return {
          autocompletedResults: state.results
      onSearch: async state => {
        const { resultsPerPage } = state;
        const requestBody = buildRequest(state);
        // Note that this could be optimized by running all of these requests
        // at the same time. Kept simple here for clarity.
        const responseJson = await runRequest(requestBody);
    // const responseJsonWithDisjunctiveFacetCounts = await applyDisjunctiveFaceting(responseJson, state, ['visitors', 'states']);
        // return buildState(responseJsonWithDisjunctiveFacetCounts, resultsPerPage);
        return buildState(responseJson, resultsPerPage);

I´m able to get the documentID and even make the query but I don´t know how to display the result.

@Daniel_Pacheco What is currently happening when a user selects an option from the dropdown? What would you like to happen instead?

Hi @JasonStoltz thanks for the response. Right now after a user selects an option, the results section do not change, keeps showing the results of the previous search, or it stays empty if no search was performed.

It looks like you're trying to perform the new request in onAutocompleteResultClick.

You do not need to perform the new request in the onAutocompleteResultClick handler. That handler is predominantly used for things like click tracking and analytics.

There are two things that the autocomplete can show. Results and Suggestions.

By default, if you click on a Suggestion, Search UI will trigger a new search which ultimately calls the onSearch you have implemented.

If you click on a Result, Search UI will open the result page for that result, based on whatever you have configured for urlField: search-ui/ at master · elastic/search-ui · GitHub

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