Mapping a completion suggester

In order to provide search functionalities for your user, one of the most common requirements is to provide text suggestions for your query.

ElasticSearch provides a helper to archive this functionality via a special type mapping called completion.

Getting ready

You need a working ElasticSearch cluster.

How to do it...

The definition of a completion field is similar to that of the previous core type fields. For example, to provide suggestions for a name with an alias, you can write a similar mapping:

{
  "name": {"type": "string", "copy_to":["suggest"]},
  "alias": {"type": "string", "copy_to":["suggest"]},
  "suggest": {
    "type": "complection",
    "payloads": true,
    "index_analyzer": "simple",
    "search_analyzer": "simple"
  }
}

In this ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.