[Search UI] Elasticsearch connector throwing error in connector.onAutocomplete

Hello I followed this tutorial Search UI with Elasticsearch | Elastic Documentation and used my own index schema. but I can't get connector.onAutocomplete to work. here is an example:

config = {
   ...search_config
      suggestions: {
         types: {
            documents: { fields: ['type'] },
         },
       size: 4,
       },
    apiConnector: apiConnector
}

I also moved the connector logic to a nextjs backend following NextJS with Elasticsearch Connector | Elastic Documentation and when I trigger await connector.onAutocomplete(requestState, queryConfig); I get the following error:

Cannot read property 'suggest' of undefined
    at CompletionSuggester.<anonymous> (/Users/amineafia/projects/blocktorch/blocktorch-app/node_modules/@searchkit/sdk/lib/cjs/suggestors/CompletionSuggestor.js:40:47)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/amineafia/projects/blocktorch/blocktorch-app/node_modules/@searchkit/sdk/lib/cjs/suggestors/CompletionSuggestor.js:5:58)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {stack: 'TypeError: Cannot read property 'suggest' of …ctions (internal/process/task_queues.js:95:5)', message: 'Cannot read property 'suggest' of undefined'}

Can you please help! what am I missing?

Happy to offer more information if needed

Hey! Is the field type a completion type? Could you share the mapping for type field

Joe

Here is the mapping:

{
 "properties":
  #other_mappings...
      "type": {
         "type": "text",
            "fields": {
               "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
               },
          "suggest": {
             "type": "search_as_you_type",
             "doc_values": false,
             "max_shingle_size": 3
          }
        }
      }

I added the "search_as_you_type" type is the right type for autocomplete right?

Ah it needs to be a completion type and the field you need to use is "type.suggest" rather than "type". Suggesters | Elasticsearch Guide [7.17] | Elastic

update the configuration to

documents: { fields: ['type.suggest'] },

The mapping should look like this:

      "type": {
         "type": "text",
            "fields": {
               "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
               },
          "suggest": {
             "type": "completion"
          }
        }
      }

Hope this helps.

Joe

Thank you for your help joemcelroy!!