Problem with phrase suggestor

Hello
I created an index using the below code

PUT test
{
  "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"
            }
          }
        }
      }
    }
  }
}

then i placed some data into that by the below code.

POST test/test?refresh=true
{"title": "noble warriors"}

POST test/test?refresh=true
{"title": "nobel prize"}

POST test/test?refresh=true
{"title": "nobele prize"}

and then tried the phrase suggestor by the below code :-

POST test/_search
{
  "suggest": {
    "text" : "nobl prize",
    "simple_phrase" : {
      "phrase" : {
        "field" : "title.trigram",
        "size" : 1,
        "direct_generator" : [ {
          "field" : "title.trigram",
          "suggest_mode" : "always"
        }, {
          "field" : "title.reverse",
          "suggest_mode" : "always",
          "pre_filter" : "reverse",
          "post_filter" : "reverse"
        } ]
      }
    }
  }
} 

received the below result :-

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "simple_phrase": [
      {
        "text": "nobl prize",
        "offset": 0,
        "length": 10,
        "options": [
          {
            "text": "nobel prize",
            "score": 0.52381706
          }
        ]
      }
    ]
  }
}

The problem with search is as below :-

  1. The Expected output should be 2 option as below
    {"title": "nobel prize"}
    {"title": "nobele prize"}
    as they both are present in the index ..

  2. when i try search nobal preze or nobl preze then i receive the result after correction of only one word..that preze into prize also when i search for nobal prize or nobl prize then i received nobl or nobal into nobel

pls guide..

If you set size to 1 then only one suggestion is returned. I tried with a size of 2 and both suggestions are returned as expected.
Regarding your second question, the phrase suggester has a parameter to control the number of terms that can be corrected in the response: max_errors. It defaults to 1 so only one term is replaced, using 2 allows the entire query terms to be replaced in your example.
Though the docs says:

Low values like 1 or 2 are recommended otherwise the time spend in suggest calls might exceed the time spend in query execution.

so check the performance hit when you set this value :wink:

@jimczi..This Works :smile: ...i Had One Small Question to ask like ...Say I Type Nobl Preze Winar with max_error = 3 ..then Do You think that it will Get It Self Changed to Nobel Prize Winner ... the Result I am getting is Nobel Prize Winar ...How Can We Use Some NLP along with this...

Pls Guide...