Skip to content

Commit 1f4b417

Browse files
sudo-suhasnik9000
authored andcommitted
Update reference docs for Highlighter fragmenter (#23754)
Explain the fragmenter and add examples.
1 parent 5ba4ee5 commit 1f4b417

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

docs/reference/search/request/highlighting.asciidoc

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,128 @@ GET /_search
401401
// CONSOLE
402402
// TEST[setup:twitter]
403403

404+
==== Fragmenter
405+
406+
Fragmenter can control how text should be broken up in highlight snippets.
407+
However, this option is applicable only for the Plain Highlighter.
408+
There are two options:
409+
410+
[horizontal]
411+
`simple`:: Breaks up text into same sized fragments.
412+
`span`:: Same as the simple fragmenter, but tries not to break up text between highlighted terms (this is applicable when using phrase like queries). This is the default.
413+
414+
[source,js]
415+
--------------------------------------------------
416+
GET twitter/tweet/_search
417+
{
418+
"query" : {
419+
"match_phrase": { "message": "number 1" }
420+
},
421+
"highlight" : {
422+
"fields" : {
423+
"message" : {
424+
"fragment_size" : 15,
425+
"number_of_fragments" : 3,
426+
"fragmenter": "simple"
427+
}
428+
}
429+
}
430+
}
431+
--------------------------------------------------
432+
// CONSOLE
433+
// TEST[setup:twitter]
434+
435+
Response:
436+
437+
[source,js]
438+
--------------------------------------------------
439+
{
440+
...
441+
"hits": {
442+
"total": 1,
443+
"max_score": 1.4818809,
444+
"hits": [
445+
{
446+
"_index": "twitter",
447+
"_type": "tweet",
448+
"_id": "1",
449+
"_score": 1.4818809,
450+
"_source": {
451+
"user": "test",
452+
"message": "some message with the number 1",
453+
"date": "2009-11-15T14:12:12",
454+
"likes": 1
455+
},
456+
"highlight": {
457+
"message": [
458+
" with the <em>number</em>",
459+
" <em>1</em>"
460+
]
461+
}
462+
}
463+
]
464+
}
465+
}
466+
--------------------------------------------------
467+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,/]
468+
469+
[source,js]
470+
--------------------------------------------------
471+
GET twitter/tweet/_search
472+
{
473+
"query" : {
474+
"match_phrase": { "message": "number 1" }
475+
},
476+
"highlight" : {
477+
"fields" : {
478+
"message" : {
479+
"fragment_size" : 15,
480+
"number_of_fragments" : 3,
481+
"fragmenter": "span"
482+
}
483+
}
484+
}
485+
}
486+
--------------------------------------------------
487+
// CONSOLE
488+
// TEST[setup:twitter]
489+
490+
Response:
491+
492+
[source,js]
493+
--------------------------------------------------
494+
{
495+
...
496+
"hits": {
497+
"total": 1,
498+
"max_score": 1.4818809,
499+
"hits": [
500+
{
501+
"_index": "twitter",
502+
"_type": "tweet",
503+
"_id": "1",
504+
"_score": 1.4818809,
505+
"_source": {
506+
"user": "test",
507+
"message": "some message with the number 1",
508+
"date": "2009-11-15T14:12:12",
509+
"likes": 1
510+
},
511+
"highlight": {
512+
"message": [
513+
"some message with the <em>number</em> <em>1</em>"
514+
]
515+
}
516+
}
517+
]
518+
}
519+
}
520+
--------------------------------------------------
521+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,/]
522+
523+
If the `number_of_fragments` option is set to `0`,
524+
`NullFragmenter` is used which does not fragment the text at all.
525+
This is useful for highlighting the entire content of a document or field.
404526

405527
==== Highlight query
406528

0 commit comments

Comments
 (0)