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]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"fields" : {
"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
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]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"fields" : {
"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
@ -148,8 +156,11 @@ stored separately. Defaults to `false`.
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"fields" : {
"content" : {"force_source" : true}
@ -157,6 +168,7 @@ stored separately. Defaults to `false`.
}
}
--------------------------------------------------
// CONSOLE
[[tags]]
==== Highlighting Tags
@ -167,8 +179,11 @@ for example:
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"pre_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"
is ordered.
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"pre_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
called `styled` with the following `pre_tags`:
@ -213,8 +233,11 @@ is an example of switching tag schemas:
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"tags_schema" : "styled",
"fields" : {
@ -223,6 +246,7 @@ is an example of switching tag schemas:
}
}
--------------------------------------------------
// CONSOLE
==== Encoder
@ -240,8 +264,11 @@ For example:
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"fields" : {
"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
outputs sentences regardless of their length.
@ -258,8 +286,11 @@ to be sorted by score:
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"order" : "score",
"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
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]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"fields" : {
"_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`
parameter to control the margin to start highlighting from.
@ -302,8 +338,11 @@ greater than `0`.
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"fields" : {
"content" : {
@ -315,6 +354,7 @@ greater than `0`.
}
}
--------------------------------------------------
// CONSOLE
==== 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`.
[source,js]
--------------------------------------------------
GET /_search
{
"fields": [ "_id" ],
"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
highlighting framework. For implementation details you can check the
@ -400,12 +442,14 @@ at the field level.
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"number_of_fragments" : 3,
"fragment_size" : 150,
"tag_schema" : "styled",
"fields" : {
"_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] },
"bio.title" : { "number_of_fragments" : 0 },
@ -415,6 +459,7 @@ at the field level.
}
}
--------------------------------------------------
// CONSOLE
[[field-match]]
==== Require Field Match
@ -426,14 +471,20 @@ match will be highlighted.
[source,js]
--------------------------------------------------
GET /_search
{
"query" : {...},
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"require_field_match": false
"fields" : {...}
"require_field_match": false,
"fields": {
"_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] }
}
}
}
--------------------------------------------------
// CONSOLE
[[boundary-characters]]
==== Boundary Characters
@ -462,6 +513,7 @@ analyzer and `content.plain` is analyzed by the `standard` analyzer.
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"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"
and would highlight "running" and "scissors" but not "run". If both
phrases appear in a large document then "running with scissors" is
@ -488,6 +541,7 @@ are more matches in that fragment.
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"query_string": {
@ -506,12 +560,14 @@ are more matches in that fragment.
}
}
--------------------------------------------------
// CONSOLE
The above highlights "run" as well as "running" and "scissors" but
still sorts "running with scissors" above "run with scissors" because
the plain match ("running") is boosted.
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"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
it is just fine not to list the field to which the matches are combined
(`content`) in the matched fields.