Merge pull request #18424 from MaineC/docs/add_console_to_highlighting

Docs/add console to highlighting
This commit is contained in:
Isabel Drost-Fromm 2016-05-24 12:14:36 +02:00
commit ea3320e171
1 changed files with 73 additions and 15 deletions

View File

@ -8,8 +8,11 @@ The following is an example of the search request body:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"fields" : { "fields" : {
"content" : {} "content" : {}
@ -17,6 +20,7 @@ The following is an example of the search request body:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
In the above case, the `content` field will be highlighted for each In the above case, the `content` field will be highlighted for each
search hit (there will be another element in each search hit, called search hit (there will be another element in each search hit, called
@ -131,8 +135,11 @@ The following is an example that forces the use of the plain highlighter:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"fields" : { "fields" : {
"content" : {"type" : "plain"} "content" : {"type" : "plain"}
@ -140,6 +147,7 @@ The following is an example that forces the use of the plain highlighter:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
==== Force highlighting on source ==== Force highlighting on source
@ -148,8 +156,11 @@ stored separately. Defaults to `false`.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"fields" : { "fields" : {
"content" : {"force_source" : true} "content" : {"force_source" : true}
@ -157,6 +168,7 @@ stored separately. Defaults to `false`.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
[[tags]] [[tags]]
==== Highlighting Tags ==== Highlighting Tags
@ -167,8 +179,11 @@ for example:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"pre_tags" : ["<tag1>"], "pre_tags" : ["<tag1>"],
"post_tags" : ["</tag1>"], "post_tags" : ["</tag1>"],
@ -178,14 +193,18 @@ for example:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
Using the fast vector highlighter there can be more tags, and the "importance" Using the fast vector highlighter there can be more tags, and the "importance"
is ordered. is ordered.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"], "pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"], "post_tags" : ["</tag1>", "</tag2>"],
@ -195,6 +214,7 @@ is ordered.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
There are also built in "tag" schemas, with currently a single schema There are also built in "tag" schemas, with currently a single schema
called `styled` with the following `pre_tags`: called `styled` with the following `pre_tags`:
@ -213,8 +233,11 @@ is an example of switching tag schemas:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"tags_schema" : "styled", "tags_schema" : "styled",
"fields" : { "fields" : {
@ -223,6 +246,7 @@ is an example of switching tag schemas:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
==== Encoder ==== Encoder
@ -240,8 +264,11 @@ For example:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"fields" : { "fields" : {
"content" : {"fragment_size" : 150, "number_of_fragments" : 3} "content" : {"fragment_size" : 150, "number_of_fragments" : 3}
@ -249,6 +276,7 @@ For example:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
The `fragment_size` is ignored when using the postings highlighter, as it The `fragment_size` is ignored when using the postings highlighter, as it
outputs sentences regardless of their length. outputs sentences regardless of their length.
@ -258,8 +286,11 @@ to be sorted by score:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"order" : "score", "order" : "score",
"fields" : { "fields" : {
@ -268,6 +299,7 @@ to be sorted by score:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
If the `number_of_fragments` value is set to `0` then no fragments are If the `number_of_fragments` value is set to `0` then no fragments are
produced, instead the whole content of the field is returned, and of produced, instead the whole content of the field is returned, and of
@ -277,8 +309,11 @@ is required. Note that `fragment_size` is ignored in this case.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"fields" : { "fields" : {
"_all" : {}, "_all" : {},
@ -287,6 +322,7 @@ is required. Note that `fragment_size` is ignored in this case.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
When using `fvh` one can use `fragment_offset` When using `fvh` one can use `fragment_offset`
parameter to control the margin to start highlighting from. parameter to control the margin to start highlighting from.
@ -302,8 +338,11 @@ greater than `0`.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"fields" : { "fields" : {
"content" : { "content" : {
@ -315,6 +354,7 @@ greater than `0`.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
==== Highlight query ==== Highlight query
@ -330,6 +370,7 @@ Generally it is better to include the search query in the
query and the rescore query in `highlight_query`. query and the rescore query in `highlight_query`.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"fields": [ "_id" ], "fields": [ "_id" ],
"query" : { "query" : {
@ -385,6 +426,7 @@ query and the rescore query in `highlight_query`.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
Note that the score of text fragment in this case is calculated by the Lucene Note that the score of text fragment in this case is calculated by the Lucene
highlighting framework. For implementation details you can check the highlighting framework. For implementation details you can check the
@ -400,12 +442,14 @@ at the field level.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"number_of_fragments" : 3, "number_of_fragments" : 3,
"fragment_size" : 150, "fragment_size" : 150,
"tag_schema" : "styled",
"fields" : { "fields" : {
"_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] }, "_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] },
"bio.title" : { "number_of_fragments" : 0 }, "bio.title" : { "number_of_fragments" : 0 },
@ -415,6 +459,7 @@ at the field level.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
[[field-match]] [[field-match]]
==== Require Field Match ==== Require Field Match
@ -426,14 +471,20 @@ match will be highlighted.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query" : {...}, "query" : {
"match": { "user": "kimchy" }
},
"highlight" : { "highlight" : {
"require_field_match": false "require_field_match": false,
"fields" : {...} "fields": {
"_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] }
}
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
[[boundary-characters]] [[boundary-characters]]
==== Boundary Characters ==== Boundary Characters
@ -462,6 +513,7 @@ analyzer and `content.plain` is analyzed by the `standard` analyzer.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query": { "query": {
"query_string": { "query_string": {
@ -480,6 +532,7 @@ analyzer and `content.plain` is analyzed by the `standard` analyzer.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
The above matches both "run with scissors" and "running with scissors" The above matches both "run with scissors" and "running with scissors"
and would highlight "running" and "scissors" but not "run". If both and would highlight "running" and "scissors" but not "run". If both
phrases appear in a large document then "running with scissors" is phrases appear in a large document then "running with scissors" is
@ -488,6 +541,7 @@ are more matches in that fragment.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query": { "query": {
"query_string": { "query_string": {
@ -506,12 +560,14 @@ are more matches in that fragment.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
The above highlights "run" as well as "running" and "scissors" but The above highlights "run" as well as "running" and "scissors" but
still sorts "running with scissors" above "run with scissors" because still sorts "running with scissors" above "run with scissors" because
the plain match ("running") is boosted. the plain match ("running") is boosted.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
GET /_search
{ {
"query": { "query": {
"query_string": { "query_string": {
@ -530,6 +586,8 @@ the plain match ("running") is boosted.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
The above query wouldn't highlight "run" or "scissor" but shows that The above query wouldn't highlight "run" or "scissor" but shows that
it is just fine not to list the field to which the matches are combined it is just fine not to list the field to which the matches are combined
(`content`) in the matched fields. (`content`) in the matched fields.