Browse Source

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
Nik Everett 4 years ago
parent
commit
0623b03170
1 changed files with 40 additions and 4 deletions
  1. 40 4
      docs/reference/search/search.asciidoc

+ 40 - 4
docs/reference/search/search.asciidoc

@@ -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