1
votes

Hi i'm new on elasticsearch and for now i indexed a website and i would like to get a text extract with the word(s) of my query,

Example I index

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi nec odio in magna blandit porta quis a nibh. Integer sodales ex ut sagittis venenatis. Duis efficitur ligula ac magna tincidunt, in iaculis magna facilisis. Nullam pulvinar diam vitae elit auctor auctor a a urna. Fusce accumsan non magna non fermentum. Curabitur dapibus tempus nisi, efficitur mattis magna aliquam nec. In hac habitasse platea dictumst. In lacus nulla, feugiat vitae neque ac, aliquam hendrerit orci.

If i request Nullam pulvinar i would like to get an extract like

Nullam pulvinar diam vitae elit auctor auctor a a urna.

Is it possible ?

1

1 Answers

3
votes

You can use Highlighting for this purpose. From the Docs

{
    "query" : {...},
    "highlight" : {
        "fields" : {
            "content" : {}
        }
    }
}

You can also specify fragment_size and number_of_fragments depending on your requirements.