Skip to content

Add document highlighter to percolate api  #3574

@martijnvg

Description

@martijnvg

Add document highlighting to percolate api, that highlights for each matching percolator query snippets inside the document being percolated.

All highlight options that are supported via the search api are also supported in the percolate api. The size option is a required option if highlighting is specified in the percolate api.

Percolate highlight example

Index document:

curl -XPUT 'localhost:9200/my-index/_percolator/1' -d '{ 
    "query": { 
        "match" : { 
            "body" : "brown fox"  
        }   
    } 
}'

Index second document:

curl -XPUT 'localhost:9200/my-index/_percolator/2' -d '{ 
    "query": { 
        "match" : { 
            "body" : "lazy dog"  
        }   
    } 
}'

Percolate request:

curl -XGET 'localhost:9200/my-index/my-type/percolate' -d '{
    "doc" : {
        "body" : "The quick brown fox jumps over the lazy dog"
    },
    "highlight" : {
        "fields" : {
            "body" : {}
        }
    },
    "size" : 5
}'

Percolate response:

{
   "took": 18,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "total": 2,
   "matches": [
      {
         "_index": "my-index",
         "_id": "1",
         "highlight": {
            "body": [
               "The quick <em>brown</em> <em>fox</em> jumps over the lazy dog"
            ]
         }
      },
      {
         "_index": "my-index",
         "_id": "2",
         "highlight": {
            "body": [
               "The quick brown fox jumps over the <em>lazy</em> <em>dog</em>"
            ]
         }
      }
   ]
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions