@@ -372,6 +372,128 @@ GET /_search
372372--------------------------------------------------
373373// CONSOLE
374374
375+ ==== Fragmenter
376+
377+ Fragmenter can control how text should be broken up in highlight snippets.
378+ However, this option is applicable only for the Plain Highlighter.
379+ There are two options:
380+
381+ [horizontal]
382+ `simple`:: Breaks up text into same sized fragments.
383+ `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.
384+
385+ [source,js]
386+ --------------------------------------------------
387+ GET twitter/tweet/_search
388+ {
389+ "query" : {
390+ "match_phrase": { "message": "number 1" }
391+ },
392+ "highlight" : {
393+ "fields" : {
394+ "message" : {
395+ "fragment_size" : 15,
396+ "number_of_fragments" : 3,
397+ "fragmenter": "simple"
398+ }
399+ }
400+ }
401+ }
402+ --------------------------------------------------
403+ // CONSOLE
404+ // TEST[setup:twitter]
405+
406+ Response:
407+
408+ [source,js]
409+ --------------------------------------------------
410+ {
411+ ...
412+ "hits": {
413+ "total": 1,
414+ "max_score": 1.4818809,
415+ "hits": [
416+ {
417+ "_index": "twitter",
418+ "_type": "tweet",
419+ "_id": "1",
420+ "_score": 1.4818809,
421+ "_source": {
422+ "user": "test",
423+ "message": "some message with the number 1",
424+ "date": "2009-11-15T14:12:12",
425+ "likes": 1
426+ },
427+ "highlight": {
428+ "message": [
429+ " with the <em>number</em>",
430+ " <em>1</em>"
431+ ]
432+ }
433+ }
434+ ]
435+ }
436+ }
437+ --------------------------------------------------
438+ // TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,/]
439+
440+ [source,js]
441+ --------------------------------------------------
442+ GET twitter/tweet/_search
443+ {
444+ "query" : {
445+ "match_phrase": { "message": "number 1" }
446+ },
447+ "highlight" : {
448+ "fields" : {
449+ "message" : {
450+ "fragment_size" : 15,
451+ "number_of_fragments" : 3,
452+ "fragmenter": "span"
453+ }
454+ }
455+ }
456+ }
457+ --------------------------------------------------
458+ // CONSOLE
459+ // TEST[setup:twitter]
460+
461+ Response:
462+
463+ [source,js]
464+ --------------------------------------------------
465+ {
466+ ...
467+ "hits": {
468+ "total": 1,
469+ "max_score": 1.4818809,
470+ "hits": [
471+ {
472+ "_index": "twitter",
473+ "_type": "tweet",
474+ "_id": "1",
475+ "_score": 1.4818809,
476+ "_source": {
477+ "user": "test",
478+ "message": "some message with the number 1",
479+ "date": "2009-11-15T14:12:12",
480+ "likes": 1
481+ },
482+ "highlight": {
483+ "message": [
484+ "some message with the <em>number</em> <em>1</em>"
485+ ]
486+ }
487+ }
488+ ]
489+ }
490+ }
491+ --------------------------------------------------
492+ // TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,/]
493+
494+ If the `number_of_fragments` option is set to `0`,
495+ `NullFragmenter` is used which does not fragment the text at all.
496+ This is useful for highlighting the entire content of a document or field.
375497
376498==== Highlight query
377499
0 commit comments