ElasticSearch suggesting from the middle of the phrase

262 views Asked by At

Please help me with choosing ElasticSearch suggesting type.

I have ElasticSearch index with big amount of companies, which have names like: "JSC Some company", "JSC Another company" and so on.

The Completion suggester doesn't work because user prefer type: "Some co..." but suggester works only if user starts with "JSC Some co..."

Is there any way to create quick search during user typing?

I want to add my mapping example and suggest query example in order get question more clear:

curl -XPUT 'localhost:9200/tass_suggest_test/_mapping/company?pretty' -H 'Content-Type: application/json' -d'
{
   "company": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "inn": {
                    "type": "keyword"
                },
                "innSuggest" : {
                    "type" : "completion",
                    "analyzer": "whitespace"
                }
            }
        }
}
'

curl -XGET 'localhost:9200/tass_suggest_test/_suggest?pretty' -H 'Content-Type: application/json' -d'
{
    "company-suggest" : {
        "prefix" : "78200",
        "completion" : {
            "field" : "innSuggest"
        }
    }
}
'
1

There are 1 answers

1
user732456 On

You can try using an ngram filter in the following manner.

"filter": {
    "suggest_filter": {
         "type"    : "ngram",
         "min_gram": 2,
         "max_gram": 7
     }
},
"analyzer": {
    "suggest_analyzer": {
         "type": "custom",
         "tokenizer": "whitespace",
         "filter": ["lowercase", "suggest_filter"]
     }
}