Elastic Search FVH highlights the smallest matching token

377 Views Asked by At

Settings:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "idx_analyzer_ngram": {
          "type": "custom",
          "filter": [
            "lowercase",
            "asciifolding",
            "edgengram_filter_1_32"
          ],
          "tokenizer": "ngram_alltokenchar_tokenizer_1_32"
        },
        "ngrm_srch_analyzer": {
          "filter": [
            "lowercase"
          ],
          "type": "custom",
          "tokenizer": "keyword"
        }
      },
      "tokenizer": {
        "ngram_alltokenchar_tokenizer_1_32": {
          "token_chars": [
            "letter",
            "whitespace",
            "punctuation",
            "symbol",
            "digit"
          ],
          "min_gram": "1",
          "type": "nGram",
          "max_gram": "32"
        }
      }
    }
  }
}

Mappings:

{
  "properties": {
    "TITLE": {
      "type": "string",
      "fields": {
        "untouched": {
          "index": "not_analyzed",
          "type": "string"
        },
        "ngramanalyzed": {
          "search_analyzer": "ngrm_srch_analyzer",
          "index_analyzer": "idx_analyzer_ngram",
          "type": "string",
          "term_vector": "with_positions_offsets"
        }
      }
    }
  }
}

Query:

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "have some ha",
          "fields": [
            "TITLE.ngramanalyzed"
          ],
          "default_operator": "and"
        }
      }
    }
  },
  "highlight": {
    "fields": {
      "TITLE.ngramanalyzed": {}
    }
  }
}

I have document indexed with TITLE have some happy meal. When I search have some, I am able to get proper highlights.

<em>have</em> <em>some</em> happy meal

As i type more have some ha, the highlight results are not as expected.

<em>ha</em>ve <em>some</em> <em>ha</em>ppy meal

The have word gets partially highlighted as ha.

I would expect it to highlight the longest matching token, because with an ngrams with min size = 1, this gives me a highlight of 1 or more char while there should be another matching token of 4 or 5 chars (for example: have should also be highlighted along with ha being highlighted.

I am not able to find any solution for the same. Please suggest.

0

There are 0 best solutions below