From 9950afbabea756d9bb88869965acc4aad8062c66 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 13 Apr 2021 08:59:27 -0400 Subject: [PATCH] Fit runtime field on line (backport #71470) (#71600) This shrinks a runtime field definition so that it fits on the screen without scrolling. It also converts the doc into a test so we can be sure it continues to work. Relates to #69291 --- docs/reference/search/search.asciidoc | 45 ++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/docs/reference/search/search.asciidoc b/docs/reference/search/search.asciidoc index 2ef6c643c49ab..df9d3826d093e 100644 --- a/docs/reference/search/search.asciidoc +++ b/docs/reference/search/search.asciidoc @@ -452,15 +452,52 @@ script has access to the entire context of a document, including the original Your script must include `emit` to return calculated values. For example: + -[source,js] +[source,js,indent=0] ---- -"script": { - "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))" - } +include::search.asciidoc[tag=runtime-script] ---- // NOTCONSOLE ==== +//// +[source,console] +---- +POST _search?size=1&filter_path=hits.hits +{ + "runtime_mappings": { + "dow": { + "type": "keyword", + // tag::runtime-script[] + "script": "emit(doc['@timestamp'].value.dayOfWeekEnum.toString())" + // end::runtime-script[] + } + }, + "fields": [{"field": "dow"}] +} +---- +// TEST[setup:my_index] + +[source,console-result] +---- +{ + "hits": { + "hits": [ + { + "_index": $body.hits.hits.0._index, + "_type": "_doc", + "_id": $body.hits.hits.0._id, + "_score": $body.hits.hits.0._score, + "_source": $body.hits.hits.0._source, + "fields": { + "dow": ["SUNDAY"] + } + } + ] + } +} +---- +//// + [[request-body-search-seq-no-primary-term]] `seq_no_primary_term`:: (Optional, Boolean) If `true`, returns sequence number and primary term of the