elasticsearch/elasticsearch — pull request #5880 by nik9000 (2014-04-19 02:15:05+00:00)
Title: Add support for conditional highlighting

Adds a "conditional" object under each highlighting field that can contain
other fields. Those fields are highlighted based on if there was a match
in the containing field.

It'll let you do things like this example in the docs:

This example extracts extracts the first 100 characters from `text` if there is
a match in `title`, otherwise it highlights `text` as normal.

{
"highlight": {
"fields": {
"title": {
"conditional": {
"match": {
"text": {
"no_match_size": 100,
"skip_matching": true
}
}
"no_match": {
"text": {
"no_match_size": 100
}
},
}
}
}
}
}

Also adds a setting to instruct the highlighter to skip its normal match
logic and just do its no_match_size stuff. This is very useful with
conditional highlighting "chains" that end in a no_match_size extracting
a previous entry in the chain. Like this example from the docs:
{
"highlight": {
"fields": {
"text": {
"conditional": {
"no_match": {
"auxiliary_text": {
"conditional": {
"no_match": {
"file_text": {
"conditional": {
"no_match": {
"text": {
"no_match_size": 100,
"skip_matching": true
}
}
}
}
}
}
}
}
}
}
}
}
}

Closes #4649