Elastic search - highlights in the center of fragments

Viewed 489

summary

I'm using Elastic search 5.2 for querying multiple fields of a document, and the response is highlighted. However I want the highlight to appear in the centre of the resulting fragment - it is persistently coming at the end of a fragment instead

  • expected fragment: text text text <em>highlighted</em> text text text
  • actual fragment: text text text text text <em>highlighted</em>

I have tried using plain, postings, and fast vector highlighter (see below) but have no luck moving the <em> tags within each fragment. Using the vector highlighter seems to have some effect, but then the fragments are coming back far too long, even when I have made changes to the boundary detector

Example index

{
    "settings": {
        "analysis": {
            "analyzer": {
                "my_analyzer": {
                    "tokenizer": "my_tokenizer",
                    "filter": [ "lowercase" ],
                },
            },
            "tokenizer": {
                "my_tokenizer": {
                    "type": "edge_ngram",
                    "min_gram": 3,
                    "max_gram": 25,
                    "token_chars": [ "letter", "digit" ],
                },
            },
        },
    },
    "mappings": {
        "doc": {
            "properties": {
                "page_text": {
                    "type": "text",
                    // "term_vector": "with_positions_offsets", // enable     this for FVH
                    "analyzer": "my_analyzer",
                },
            },
        },
    },
}

Example query

{
    "query": {
        "match_phrase_prefix" : {
            "page_text" : {
                "query" : "position",
            },
        },
    },
}

Example output fragment: ming it. Then so does over sent dull on. Likewise offended humoured mrs fat trifling answered. On ye <em>position</em>

Ideally the example output would have more of the fragment after the closing </em>

Second example fragment, with the search term "posit": ming it. Then so does over sent dull on. Likewise offended humoured mrs fat trifling answered. On ye <em>posit</em>

The string "posit" is returned as part of the word "position" again, but this time the word is cut in half

How best to correct this?

0 Answers
Related