Query_suggestion does not work on Elasticsearch-index based engine

I have an issue where queries to enterprisesearch's app_search (8.8.2) "query_suggestion" endpoint does not return suggestions when the engine is based on an elasticsearch index.

The endpoint works and are returning suggestions when creating an engine where the documents are created in Enterprisesearch (or when I create an engine based on the preset test data).

I suspect that my index is not setup correctly, to this is my index:

{
  "elasticsearch_index_drupal_content": {
    "aliases": {
      "search-elasticsearch-index-drupal-content-alias": {}
    },
    "mappings": {
      "properties": {
        "_language": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "field_business_types": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "field_responsible": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "nid": {
          "type": "long"
        },
        "node_grants": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "rendered_content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "status": {
          "type": "boolean"
        },
        "title": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "topics_hierarchy": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "type": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "type_label": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "uid": {
          "type": "long"
        },
        "url": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "routing": {
          "allocation": {
            "include": {
              "_tier_preference": "data_content"
            }
          }
        },
        "number_of_shards": "1",
        "provided_name": "elasticsearch_index_drupal_content",
        "creation_date": "1688403423531",
        "number_of_replicas": "1",
        "uuid": "YFgRe52dQha7TqZK-BnV_w",
        "version": {
          "created": "8080299"
        }
      }
    }
  }
}

Hi @JohMat !

Some App Search features depend on these field conventions.

For query suggestion to work, you need to have a prefix multifield on the fields you want to perform query suggestions to work. This prefix multifield needs to have the expected analyzers for query suggestion to work.

This is a simplified mapping and settings for adding this field for your title field:

{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          },
          "prefix": {
            "type": "text",
            "index_options": "docs",
            "analyzer": "i_prefix",
            "search_analyzer": "q_prefix"
          }
        }
      }
    }
  },
  "settings": {
    "analysis": {
      "filter": {
        "front_ngram": {
          "type": "edge_ngram",
          "min_gram": "1",
          "max_gram": "12"
        }
      },
      "analyzer": {
        "i_prefix": {
          "filter": [
            "lowercase",
            "front_ngram"
          ],
          "tokenizer": "standard"
        },
        "q_prefix": {
          "filter": [
            "lowercase"
          ],
          "tokenizer": "standard"
        }
      }
    }
  }
}

You can check an index mapping created by Enterprise Search to check how these fields are created.

Once the prefix field is defined for your text fields, you will be able to get query suggestions to work.

We'll make sure to include this into the query suggestions documentation to make sure our users understand what is needed for Elasticsearch based engines to have it working.

Hope that helps!

1 Like

I see! Thank you for the quick response!
I had read the documentation on Elasticsearch engines text field conventions | App Search documentation [8.8] | Elastic but did not understand the implications for Enterprisesearch.

Could you direct me to any documentation on how I would go about to alter the index and add prefix to my mappings? I am using Kibana

I did solve it by deleting the index, then creating it again with prefix options set in the field part as shown above by @Carlos_D:

        "prefix": {
          "type": "text",
          "index_options": "docs",
        }

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