|
@@ -452,15 +452,51 @@ 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,
|
|
|
+ "_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
|