Elasticsearch - search for terms smaller than min_gram

Viewed 389

I am fairly new to Elasticsearch, but managed to produce results, almost to what I expect them to be, except one small problem. I am showing only the code that focuses on the issue. Using edgeNGram as a filter:

filter: {
  'type':'edgeNGram',
  'max_gram':10,
  'min_gram':3,
  'side': 'front',
  'minimum_should_match':'100%'
}

So, the results come out as expected, however I don't get any results for words smaller than 3 characters long. 3 characters longs give fairly good results, but 2 characters breaks the results, giving a lot of irrelevant results.

Essentially, what I would like is to use edgeNgram for 3 characters long, but also search for 2-character-long terms.

Looking forward to your suggestions!

1 Answers

Well, I've been googling this for so many days, and I just now found the solution to my own problem. The edgeNGram filter has a preserve_original option. Documentation reads:

(Optional, boolean) Emits original token when set to true. Defaults to false.

source: https://www.elastic.co/guide/en/elasticsearch//reference/current/analysis-edgengram-tokenfilter.html

This seems to be working for me and am now getting the expected results! Hope it helps someone that ends up here, it wasn't an easy find.

Related