0

How is it possible to get term suggestions by prefix, I have the name field.

I have three records:

sitting in the mid of the place

making the minimum job done

canal mib gone

I want to be able to get the word minimum as a suggested term when I type min but I do get mid and mib which are in the other documents.

This is my query:

{
  "suggest": {
    "text": "min",
    "simple_phrase": {
      "term": {
        "analyzer": "standard",
        "field": "Name.raw",
        "min_word_length": 2,
        "prefix_length": 1,
        "suggest_mode": "always"
      }
    }
  }
}

MAPPING:

{
  "Name": {
    "type": "text",
    "index": "not_analyzed",
    "include_in_all": true,
    "fields": {
      "raw": {
        "type": "text",
        "index": "not_analyzed",
        "include_in_all": false
      },
      "trigram": {
        "type": "text",
        "analyzer": "trigram_analyzer"
      }
    }
  }
}

RESULT

{
  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "simple_phrase": [
      {
        "text": "min",
        "offset": 0,
        "length": 3,
        "options": [
          {
            "text": "mib",
            "score": 0.6666666,
            "freq": 79
          },
          {
            "text": "mid",
            "score": 0.6666666,
            "freq": 59
          }
        ]
      }
    ]
  }
}
Vadim Beskrovnov
  • 941
  • 6
  • 18

1 Answers1

0

As it says in documentation:

The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. The suggested terms are provided per analyzed suggest text token. The term suggester doesn’t take the query into account that is part of request.

So, term suggestor just "edit" your text. So you can try something like this, to see minimum as suggested result:

{
  "suggest": {
    "text" : "minimam",
    "simple_phrase" : {
      "term" : {
        "analyzer" : "standard",
        "field" :  "Name.raw",
        "min_word_length" : 1,
        "suggest_mode" : "always"
      }
    }
  }
}

I think, that for your purpose it is better to use completion suggester.

Vadim Beskrovnov
  • 941
  • 6
  • 18
  • Thanks for your answer Vadim. I thought about using the completion suggester but it returns whole documents instead of tokens or keywords. So when i type min it returns the whole " making the minimum job done " which is not what i need – InternCoder Jun 18 '18 at 16:45
  • Then you can use this analyzer https://www.elastic.co/guide/en/elasticsearch/reference/6.1/analysis-word-delimiter-tokenfilter.html And use completion suggester whit it. – Vadim Beskrovnov Jun 18 '18 at 17:05