# Query\_suggestion does not work on Elasticsearch-index based engine

**URL:** <https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [July 5, 2023, 7:39am UTC](https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630 "2023-07-05T07:39:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohMat](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JohMat](https://discuss.elastic.co/u/JohMat)\
**Post date:** [July 5, 2023, 7:39am UTC](https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630/1 "2023-07-05T07:39:41Z")

</div>

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:

```auto
{
  "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"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)\
**Post date:** [July 5, 2023, 10:45am UTC](https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630/2 "2023-07-05T10:45:33Z")

</div>

Hi @JohMat !

Some App Search features depend on [these field conventions](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines-text-subfields-support-conventions.html).

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:

```json
{
  "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!

---

<div class="post-metadata">

**Author:** ![JohMat](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JohMat](https://discuss.elastic.co/u/JohMat)\
**Post date:** [July 5, 2023, 10:55am UTC](https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630/3 "2023-07-05T10:55:06Z")

</div>

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](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines-text-subfields-support-conventions.html) 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

---

<div class="post-metadata">

**Author:** ![JohMat](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JohMat](https://discuss.elastic.co/u/JohMat)\
**Post date:** [July 5, 2023, 1:03pm UTC](https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630/4 "2023-07-05T13:03:16Z")

</div>

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:

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

```

---

<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:** [August 2, 2023, 1:03pm UTC](https://discuss.elastic.co/t/query-suggestion-does-not-work-on-elasticsearch-index-based-engine/337630/5 "2023-08-02T13:03:47Z")

</div>

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