"Did you mean" feature using elasticsearch

Hi all,
I am implementing "did you mean" technology using Elasticsearch. After doing some research I found out, phrase suggesters is designed only for this purpose. But I am facing some issues with it.
My mapping document:

{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "trigram": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "shingle"]
          },
          "reverse": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "reverse"]
          }
        },
        "filter": {
          "shingle": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 3
          }
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "trigram": {
              "type": "text",
              "analyzer": "trigram"
            },
            "reverse": {
              "type": "text",
              "analyzer": "reverse"
            }
          }
        }
      }
    }
  }
}

My document is :

{"title": "nobel prize"}

My search query is:

{
  "suggest": {
    "text": "noble prze",
    "simple_phrase": {
      "phrase": {
        "field": "title.trigram",
        "size": 1,
        "gram_size": 3,
        "direct_generator": [ {
          "field": "title.trigram",
          "suggest_mode": "always"
        } ],
        "highlight": {
          "pre_tag": "<em>",
          "post_tag": "</em>"
        }
      }
    }
  }
}

The query works fine if there is mismatch with only one character in the text to be searched. Otherwise the phrase suggested corrects only one character.
The output is:

{
    "took": 6,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": 0,
        "hits": []
    },
    "suggest": {
        "simple_phrase": [
            {
                "text": "noble prze",
                "offset": 0,
                "length": 10,
                "options": [
                    {
                        "text": "nobel prze",
                        "highlighted": "<em>nobel</em> prze",
                        "score": 0.16992487
                    }
                ]
            }
        ]
    }
}

@elastic

@rjernst

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