[SOLVED] Custom Analyzer in Completion Suggest

I wanted to make an index/mapping for completion-suggester documents like:

PUT /namesuggest/_doc/1
{
  "name": "I_AM_JUST_DISPLAYED_NOT_SEARCHED",
  "name_suggest": [
        {
            "input": ["Jêánnè Pierre"],
            "weight" : 10
        }
    ]
}

and queries like:

POST /namesuggest/_search
{
  "suggest": {
    "my_suggest" : {
        "prefix" : "Jeanne",
        "completion" : {
            "field" : "name_suggest"
        }
    }
  }
}

This example produces zero results with no=custom analyzer. So after reading the official ES docs and this post https://code-examples.net/en/q/15ffd8a I tried to make a custom analyzer for the mapping of the index:

PUT /namesuggest/
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "analyzer": {
          "name_analyzer": {
              "type": "custom",
              "tokenizer": "standard",
              "filter": [
                  "lowercase",
                  "trim",
                  "my_ascii_folding"
              ]
          }
      },
      "filter": {
          "my_ascii_folding" : {
              "type" : "asciifolding",
              "preserve_original" : true
          }
      }
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "name": {"type": "keyword"},
        "name_suggest": {
          "type": "completion",
          "max_input_length": 50
        }
      }
    }
  }
}

I can successfully test what it's doing with

GET /namesuggest/_analyze
{
  "analyzer" : "name_analyzer",
  "text" : ["Jêánnè Pierre"]
}

which returns

{
  "tokens": [
    {
      "token": "jeanne",
      "start_offset": 0,
      "end_offset": 6,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "jêánnè",
      "start_offset": 0,
      "end_offset": 6,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "pierre",
      "start_offset": 7,
      "end_offset": 13,
      "type": "<ALPHANUM>",
      "position": 1
    }
  ]
}

So the lowercasing and ascii-folding works! But then why does a completion-suggest query for the prefix "Jeanne" like in the example above return 0 results? In case it matters, I am using ES 6.4

SOLVED: I just forgot to specify the analyzer in the name_suggest-property.

1 Like

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