4

Can Elasticsearch or Elastic Cloud return response with matched position?

Example request

{ "query": { "match": { "body": "apple" } } }

Ideal response

{
    "_source": {
        "body": "The red apple is a good apple."
    },
    "matched_position": [
        {
            "start": 8,
            "end": 12,
        },
        {
            "start": 24,
            "end": 28,            
        }
    ]
}
2

1 Answer 1

3

If you need the offset and not only the highlighted text, you will need to implement custom highlighter (plugin).

An example highlighter plugin: https://github.com/wikimedia/search-highlighter - note that you would have to adjust it to 7.X version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.