Skip to content

Commit 0623b03

Browse files
authored
Fit runtime field on line (#71470)
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
1 parent e4451bd commit 0623b03

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

docs/reference/search/search.asciidoc

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,51 @@ script has access to the entire context of a document, including the original
452452
Your script must include `emit` to return calculated values. For
453453
example:
454454
+
455-
[source,js]
455+
[source,js,indent=0]
456456
----
457-
"script": {
458-
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
459-
}
457+
include::search.asciidoc[tag=runtime-script]
460458
----
461459
// NOTCONSOLE
462460
====
463461

462+
////
463+
[source,console]
464+
----
465+
POST _search?size=1&filter_path=hits.hits
466+
{
467+
"runtime_mappings": {
468+
"dow": {
469+
"type": "keyword",
470+
// tag::runtime-script[]
471+
"script": "emit(doc['@timestamp'].value.dayOfWeekEnum.toString())"
472+
// end::runtime-script[]
473+
}
474+
},
475+
"fields": [{"field": "dow"}]
476+
}
477+
----
478+
// TEST[setup:my_index]
479+
480+
[source,console-result]
481+
----
482+
{
483+
"hits": {
484+
"hits": [
485+
{
486+
"_index": $body.hits.hits.0._index,
487+
"_id": $body.hits.hits.0._id,
488+
"_score": $body.hits.hits.0._score,
489+
"_source": $body.hits.hits.0._source,
490+
"fields": {
491+
"dow": ["SUNDAY"]
492+
}
493+
}
494+
]
495+
}
496+
}
497+
----
498+
////
499+
464500
[[request-body-search-seq-no-primary-term]]
465501
`seq_no_primary_term`::
466502
(Optional, Boolean) If `true`, returns sequence number and primary term of the

0 commit comments

Comments
 (0)