runtime.asciidoc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. [[runtime]]
  2. == Runtime fields
  3. Typically, you index data into {es} to promote faster search. However, indexing
  4. can be slow and requires more disk space, and you have to reindex your data to
  5. add fields to existing documents. With _runtime fields_, you can add
  6. fields to documents already indexed to {es} without reindexing your data.
  7. You access runtime fields from the search API like any other field, and {es}
  8. sees runtime fields no differently. You can define runtime fields in the
  9. <<runtime-mapping-fields,index mapping>> or in the
  10. <<runtime-search-request,search request>>. Your choice, which is part of the
  11. inherent flexibility of runtime fields.
  12. [discrete]
  13. [[runtime-benefits]]
  14. === Benefits
  15. Because runtime fields aren't indexed, adding a runtime field doesn't increase
  16. the index size. You define runtime fields directly in the index mapping, saving
  17. storage costs and increasing ingestion speed. You can more quickly ingest
  18. data into the Elastic Stack and access it right away. When you define a runtime
  19. field, you can immediately use it in search requests, aggregations, filtering,
  20. and sorting.
  21. If you make a runtime field an indexed field, you don't need to modify any
  22. queries that refer to the runtime field. Better yet, you can refer to some
  23. indices where the field is a runtime field, and other indices where the field
  24. is an indexed field. You have the flexibility to choose which fields to index
  25. and which ones to keep as runtime fields.
  26. At its core, the most important benefit of runtime fields is the ability to
  27. add fields to documents after you've ingested them. This capability simplifies
  28. mapping decisions because you don't have to decide how to parse your data up
  29. front, and can use runtime fields to amend the mapping at any time. Using
  30. runtime fields allows for a smaller index and faster ingest time, which
  31. combined use less resources and reduce your operating costs.
  32. [discrete]
  33. [[runtime-use-cases]]
  34. === Use cases
  35. Runtime fields are useful when working with log data
  36. (see <<runtime-examples,examples>>), especially when you're unsure about the
  37. data structure. Your search speed decreases, but your index size is much
  38. smaller and you can more quickly process logs without having to index them.
  39. Runtime fields are especially useful in the following contexts:
  40. * Adding fields to documents that are already indexed without having to reindex
  41. data
  42. * Immediately begin working on a new data stream without fully understanding
  43. the data it contains
  44. * Shadowing an indexed field with a runtime field to fix a mistake after
  45. indexing documents
  46. * Defining fields that are only relevant for a particular context (such as a
  47. visualization in {kib}) without influencing the underlying schema
  48. [discrete]
  49. [[runtime-compromises]]
  50. === Compromises
  51. Runtime fields use less disk space and provide flexibility in how you access
  52. your data, but can impact search performance based on the computation defined in
  53. the runtime script.
  54. To balance search performance and flexibility, index fields that you'll
  55. commonly search for and filter on, such as a timestamp. {es} automatically uses
  56. these indexed fields first when running a query, resulting in a fast response
  57. time. You can then use runtime fields to limit the number of fields that {es}
  58. needs to calculate values for. Using indexed fields in tandem with runtime
  59. fields provides flexibility in the data that you index and how you define
  60. queries for other fields.
  61. Use the <<async-search,asynchronous search API>> to run searches that include
  62. runtime fields. This method of search helps to offset the performance impacts
  63. of computing values for runtime fields in each document containing that field.
  64. If the query can't return the result set synchronously, you'll get results
  65. asynchronously as they become available.
  66. IMPORTANT: Queries against runtime fields are considered expensive. If
  67. <<query-dsl-allow-expensive-queries,`search.allow_expensive_queries`>> is set
  68. to `false`, expensive queries are not allowed and {es} will reject any queries
  69. against runtime fields.
  70. [[runtime-mapping-fields]]
  71. === Mapping a runtime field
  72. You map runtime fields by adding a `runtime` section under the mapping
  73. definition and defining
  74. <<modules-scripting-using,a Painless script>>. This script has access to the
  75. entire context of a document, including the original `_source` and any mapped
  76. fields plus their values. At search time, the script runs and generates values
  77. for each scripted field that is required for the query.
  78. NOTE: You can define a runtime field in the mapping definition without a
  79. script. At search time, {es} looks in `_source` for a field with the same name
  80. and returns a value if one exists. If a field with the same name doesn’t
  81. exist, the response doesn't include any values for that runtime field.
  82. If <<dynamic-field-mapping,dynamic field mapping>> is enabled where the
  83. `dynamic` parameter is set to `runtime`, new fields are automatically added to
  84. the index mapping as runtime fields.
  85. Runtime fields are similar to the <<script-fields,`script_fields`>> parameter
  86. of the `_search` request, but also make the script results available anywhere
  87. in a search request.
  88. The script in the following request extracts the day of the week from the
  89. `@timestamp` field, which is defined as a `date` type:
  90. [source,console]
  91. ----
  92. PUT /my-index
  93. {
  94. "mappings": {
  95. "runtime": { <1>
  96. "day_of_week": {
  97. "type": "keyword", <2>
  98. "script": { <3>
  99. "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
  100. }
  101. }
  102. },
  103. "properties": {
  104. "timestamp": {"type": "date"}
  105. }
  106. }
  107. }
  108. ----
  109. <1> Runtime fields are defined in the `runtime` section of the mapping
  110. definition.
  111. <2> Each runtime field has its own field type, just like any other field.
  112. <3> The script defines the evaluation to calculate at search time.
  113. The `runtime` section can be any of these data types:
  114. * `boolean`
  115. * `date`
  116. * `double`
  117. * `geo_point`
  118. * `ip`
  119. * `keyword`
  120. * `long`
  121. Runtime fields with a `type` of `date` can accept the
  122. <<mapping-date-format,`format`>> parameter exactly as the `date` field type.
  123. [[runtime-updating-scripts]]
  124. .Updating runtime scripts
  125. ****
  126. Updating a script while a dependent query is running can return
  127. inconsistent results. Each shard might have access to different versions of the
  128. script, depending on when the mapping change takes effect.
  129. Existing queries or visualizations in {kib} that rely on runtime fields can
  130. fail if you change the field type. For example, a bar chart visualization
  131. that uses a runtime field of type `ip` will fail if the type is changed
  132. to `boolean`.
  133. ****
  134. [[runtime-search-request]]
  135. === Defining runtime fields in a search request
  136. You can specify a `runtime_mappings` section in a search request to create
  137. runtime fields that exist only as part of the query. You specify a script
  138. as part of the `runtime_mappings` section, just as you would if adding a
  139. runtime field to the mappings.
  140. Fields defined in the search request take precedence over fields defined with
  141. the same name in the index mappings. This flexibility allows you to shadow
  142. existing fields and calculate a different value in the search request, without
  143. modifying the field itself. If you made a mistake in your index mapping, you
  144. can use runtime fields to calculate values that override values in the mapping
  145. during the search request.
  146. In the following request, the values for the `day_of_week` field are calculated
  147. dynamically, and only within the context of this search request:
  148. [source,console]
  149. ----
  150. GET my-index/_search
  151. {
  152. "runtime_mappings": {
  153. "day_of_week": {
  154. "type": "keyword",
  155. "script": {
  156. "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
  157. }
  158. }
  159. },
  160. "aggs": {
  161. "day_of_week": {
  162. "terms": {
  163. "field": "day_of_week"
  164. }
  165. }
  166. }
  167. }
  168. ----
  169. // TEST[continued]
  170. Defining a runtime field in a search request uses the same format as defining
  171. a runtime field in the index mapping. That consistency means you can promote a
  172. runtime field from a search request to the index mapping by moving the field
  173. definition from `runtime_mappings` in the search request to the `runtime`
  174. section of the index mapping.
  175. [[runtime-shadowing-fields]]
  176. === Shadowing fields
  177. If you create a runtime field with the same name as a field that
  178. already exists in the mapping, the runtime field shadows the mapped field. At
  179. search time, {es} evaluates the runtime field, calculates a value based on the
  180. script, and returns the value as part of the query. Because the runtime field
  181. shadows the mapped field, you can modify the value returned in search without
  182. modifying the mapped field.
  183. For example, let's say you indexed the following documents into `my-index`:
  184. [source,console]
  185. ----
  186. POST my-index/_bulk?refresh=true
  187. {"index":{}}
  188. {"timestamp":1516729294000,"model_number":"QVKC92Q","measures":{"voltage":5.2}}
  189. {"index":{}}
  190. {"timestamp":1516642894000,"model_number":"QVKC92Q","measures":{"voltage":5.8}}
  191. {"index":{}}
  192. {"timestamp":1516556494000,"model_number":"QVKC92Q","measures":{"voltage":5.1}}
  193. {"index":{}}
  194. {"timestamp":1516470094000,"model_number":"QVKC92Q","measures":{"voltage":5.6}}
  195. {"index":{}}
  196. {"timestamp":1516383694000,"model_number":"HG537PU","measures":{"voltage":4.2}}
  197. {"index":{}}
  198. {"timestamp":1516297294000,"model_number":"HG537PU","measures":{"voltage":4.0}}
  199. ----
  200. You later realize that the `HG537PU` sensors aren't reporting their true
  201. voltage. The indexed values are supposed to be 1.7 times higher than
  202. the reported values! Instead of reindexing your data, you can define a script in
  203. the `runtime_mappings` section of the `_search` request to shadow the `voltage`
  204. field and calculate a new value at search time.
  205. If you search for documents where the model number matches `HG537PU`:
  206. [source,console]
  207. ----
  208. GET my-index/_search
  209. {
  210. "query": {
  211. "match": {
  212. "model_number": "HG537PU"
  213. }
  214. }
  215. }
  216. ----
  217. //TEST[continued]
  218. The response includes indexed values for documents matching model number
  219. `HG537PU`:
  220. [source,console-result]
  221. ----
  222. {
  223. ...
  224. "hits" : {
  225. "total" : {
  226. "value" : 2,
  227. "relation" : "eq"
  228. },
  229. "max_score" : 1.0296195,
  230. "hits" : [
  231. {
  232. "_index" : "my-index",
  233. "_id" : "F1BeSXYBg_szTodcYCmk",
  234. "_score" : 1.0296195,
  235. "_source" : {
  236. "timestamp" : 1516383694000,
  237. "model_number" : "HG537PU",
  238. "measures" : {
  239. "voltage" : 4.2
  240. }
  241. }
  242. },
  243. {
  244. "_index" : "my-index",
  245. "_id" : "l02aSXYBkpNf6QRDO62Q",
  246. "_score" : 1.0296195,
  247. "_source" : {
  248. "timestamp" : 1516297294000,
  249. "model_number" : "HG537PU",
  250. "measures" : {
  251. "voltage" : 4.0
  252. }
  253. }
  254. }
  255. ]
  256. }
  257. }
  258. ----
  259. // TESTRESPONSE[s/\.\.\./"took" : $body.took,"timed_out" : $body.timed_out,"_shards" : $body._shards,/]
  260. // TESTRESPONSE[s/"_id" : "F1BeSXYBg_szTodcYCmk"/"_id": $body.hits.hits.0._id/]
  261. // TESTRESPONSE[s/"_id" : "l02aSXYBkpNf6QRDO62Q"/"_id": $body.hits.hits.1._id/]
  262. The following request defines a runtime field where the script evaluates the
  263. `model_number` field where the value is `HG537PU`. For each match, the script
  264. multiplies the value for the `voltage` field by `1.7`.
  265. Using the <<search-fields,`fields`>> parameter on the `_search` API, you can
  266. retrieve the value that the script calculates for the `measures.voltage` field
  267. for documents matching the search request:
  268. [source,console]
  269. ----
  270. POST my-index/_search
  271. {
  272. "runtime_mappings": {
  273. "measures.voltage": {
  274. "type": "double",
  275. "script": {
  276. "source":
  277. """if (doc['model_number.keyword'].value.equals('HG537PU'))
  278. {emit(1.7 * params._source['measures']['voltage']);}
  279. else{emit(params._source['measures']['voltage']);}"""
  280. }
  281. }
  282. },
  283. "query": {
  284. "match": {
  285. "model_number": "HG537PU"
  286. }
  287. },
  288. "fields": ["measures.voltage"]
  289. }
  290. ----
  291. //TEST[continued]
  292. Looking at the response, the calculated values for `measures.voltage` on each
  293. result are `7.14` and `6.8`. That's more like it! The runtime field calculated
  294. this value as part of the search request without modifying the mapped value,
  295. which still returns in the response:
  296. [source,console-result]
  297. ----
  298. {
  299. ...
  300. "hits" : {
  301. "total" : {
  302. "value" : 2,
  303. "relation" : "eq"
  304. },
  305. "max_score" : 1.0296195,
  306. "hits" : [
  307. {
  308. "_index" : "my-index",
  309. "_id" : "F1BeSXYBg_szTodcYCmk",
  310. "_score" : 1.0296195,
  311. "_source" : {
  312. "timestamp" : 1516383694000,
  313. "model_number" : "HG537PU",
  314. "measures" : {
  315. "voltage" : 4.2
  316. }
  317. },
  318. "fields" : {
  319. "measures.voltage" : [
  320. 7.14
  321. ]
  322. }
  323. },
  324. {
  325. "_index" : "my-index",
  326. "_id" : "l02aSXYBkpNf6QRDO62Q",
  327. "_score" : 1.0296195,
  328. "_source" : {
  329. "timestamp" : 1516297294000,
  330. "model_number" : "HG537PU",
  331. "measures" : {
  332. "voltage" : 4.0
  333. }
  334. },
  335. "fields" : {
  336. "measures.voltage" : [
  337. 6.8
  338. ]
  339. }
  340. }
  341. ]
  342. }
  343. }
  344. ----
  345. // TESTRESPONSE[s/\.\.\./"took" : $body.took,"timed_out" : $body.timed_out,"_shards" : $body._shards,/]
  346. // TESTRESPONSE[s/"_id" : "F1BeSXYBg_szTodcYCmk"/"_id": $body.hits.hits.0._id/]
  347. // TESTRESPONSE[s/"_id" : "l02aSXYBkpNf6QRDO62Q"/"_id": $body.hits.hits.1._id/]
  348. [[runtime-retrieving-fields]]
  349. === Retrieving a runtime field
  350. Use the <<search-fields,`fields`>> parameter on the `_search` API to retrieve
  351. the values of runtime fields. Runtime fields won't display in `_source`, but
  352. the `fields` API works for all fields, even those that were not sent as part of
  353. the original `_source`.
  354. The following request uses the search API to retrieve the `day_of_week` field
  355. that <<runtime-mapping-fields,this previous request>> defined as a runtime field
  356. in the mapping. The value for the `day_of_week` field is calculated dynamically
  357. at search time based on the evaluation of the defined script.
  358. [source,console]
  359. ----
  360. GET my-index/_search
  361. {
  362. "fields": [
  363. "@timestamp",
  364. "day_of_week"
  365. ],
  366. "_source": false
  367. }
  368. ----
  369. // TEST[continued]
  370. [[runtime-examples]]
  371. === Runtime fields examples
  372. Consider a large set of log data that you want to extract fields from.
  373. Indexing the data is time consuming and uses a lot of disk space, and you just
  374. want to explore the data structure without committing to a schema up front.
  375. You know that your log data contains specific fields that you want to extract.
  376. By using runtime fields, you can define scripts to calculate values at search
  377. time for these fields.
  378. You can start with a simple example by adding the `@timestamp` and `message`
  379. fields to the `my-index` mapping. To remain flexible, use `wildcard` as the
  380. field type for `message`:
  381. [source,console]
  382. ----
  383. PUT /my-index/
  384. {
  385. "mappings": {
  386. "properties": {
  387. "@timestamp": {
  388. "format": "strict_date_optional_time||epoch_second",
  389. "type": "date"
  390. },
  391. "message": {
  392. "type": "wildcard"
  393. }
  394. }
  395. }
  396. }
  397. ----
  398. After mapping the fields you want to retrieve, index a few records from
  399. your log data into {es}. The following request uses the <<docs-bulk,bulk API>>
  400. to index raw log data into `my-index`. Instead of indexing all of your log
  401. data, you can use a small sample to experiment with runtime fields.
  402. [source,console]
  403. ----
  404. POST /my-index/_bulk?refresh
  405. { "index": {}}
  406. { "@timestamp": "2020-06-21T15:00:01-05:00", "message" : "211.11.9.0 - - [2020-06-21T15:00:01-05:00] \"GET /english/index.html HTTP/1.0\" 304 0"}
  407. { "index": {}}
  408. { "@timestamp": "2020-06-21T15:00:01-05:00", "message" : "211.11.9.0 - - [2020-06-21T15:00:01-05:00] \"GET /english/index.html HTTP/1.0\" 304 0"}
  409. { "index": {}}
  410. { "@timestamp": "2020-04-30T14:30:17-05:00", "message" : "40.135.0.0 - - [2020-04-30T14:30:17-05:00] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
  411. { "index": {}}
  412. { "@timestamp": "2020-04-30T14:30:53-05:00", "message" : "232.0.0.0 - - [2020-04-30T14:30:53-05:00] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
  413. { "index": {}}
  414. { "@timestamp": "2020-04-30T14:31:12-05:00", "message" : "26.1.0.0 - - [2020-04-30T14:31:12-05:00] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
  415. { "index": {}}
  416. { "@timestamp": "2020-04-30T14:31:19-05:00", "message" : "247.37.0.0 - - [2020-04-30T14:31:19-05:00] \"GET /french/splash_inet.html HTTP/1.0\" 200 3781"}
  417. { "index": {}}
  418. { "@timestamp": "2020-04-30T14:31:27-05:00", "message" : "252.0.0.0 - - [2020-04-30T14:31:27-05:00] \"GET /images/hm_bg.jpg HTTP/1.0\" 200 24736"}
  419. { "index": {}}
  420. { "@timestamp": "2020-04-30T14:31:29-05:00", "message" : "247.37.0.0 - - [2020-04-30T14:31:29-05:00] \"GET /images/hm_brdl.gif HTTP/1.0\" 304 0"}
  421. { "index": {}}
  422. { "@timestamp": "2020-04-30T14:31:29-05:00", "message" : "247.37.0.0 - - [2020-04-30T14:31:29-05:00] \"GET /images/hm_arw.gif HTTP/1.0\" 304 0"}
  423. { "index": {}}
  424. { "@timestamp": "2020-04-30T14:31:32-05:00", "message" : "247.37.0.0 - - [2020-04-30T14:31:32-05:00] \"GET /images/nav_bg_top.gif HTTP/1.0\" 200 929"}
  425. { "index": {}}
  426. { "@timestamp": "2020-04-30T14:31:43-05:00", "message" : "247.37.0.0 - - [2020-04-30T14:31:43-05:00] \"GET /french/images/nav_venue_off.gif HTTP/1.0\" 304 0"}
  427. ----
  428. // TEST[continued]
  429. At this point, you can view how {es} stores your raw data.
  430. [source,console]
  431. ----
  432. GET /my-index
  433. ----
  434. // TEST[continued]
  435. The mapping contains two fields: `@timestamp` and `message`.
  436. [source,console-result]
  437. ----
  438. {
  439. "my-index" : {
  440. "aliases" : { },
  441. "mappings" : {
  442. "properties" : {
  443. "@timestamp" : {
  444. "type" : "date",
  445. "format" : "strict_date_optional_time||epoch_second"
  446. },
  447. "message" : {
  448. "type" : "wildcard"
  449. }
  450. }
  451. },
  452. ...
  453. }
  454. }
  455. ----
  456. // TESTRESPONSE[s/\.\.\./"settings": $body.my-index.settings/]
  457. If you want to retrieve results that include `clientip`, you can add that field
  458. as a runtime field in the mapping. The runtime script operates on the `clientip`
  459. field at runtime to calculate values for that field.
  460. [source,console]
  461. ----
  462. PUT /my-index/_mapping
  463. {
  464. "runtime": {
  465. "clientip": {
  466. "type": "ip",
  467. "script" : {
  468. "source" : "String m = doc[\"message\"].value; int end = m.indexOf(\" \"); emit(m.substring(0, end));"
  469. }
  470. }
  471. }
  472. }
  473. ----
  474. // TEST[continued]
  475. Using the `clientip` runtime field, you can define a simple query to run a
  476. search for a specific IP address and return all related fields.
  477. [source,console]
  478. ----
  479. GET my-index/_search
  480. {
  481. "size": 1,
  482. "query": {
  483. "match": {
  484. "clientip": "211.11.9.0"
  485. }
  486. },
  487. "fields" : ["*"]
  488. }
  489. ----
  490. // TEST[continued]
  491. The API returns the following result. Without building your data structure in
  492. advance, you can search and explore your data in meaningful ways to experiment
  493. and determine which fields to index.
  494. [source,console-result]
  495. ----
  496. {
  497. ...
  498. "hits" : {
  499. "total" : {
  500. "value" : 2,
  501. "relation" : "eq"
  502. },
  503. "max_score" : 1.0,
  504. "hits" : [
  505. {
  506. "_index" : "my-index",
  507. "_id" : "oWs5KXYB-XyJbifr9mrz",
  508. "_score" : 1.0,
  509. "_source" : {
  510. "@timestamp" : "2020-06-21T15:00:01-05:00",
  511. "message" : "211.11.9.0 - - [2020-06-21T15:00:01-05:00] \"GET /english/index.html HTTP/1.0\" 304 0"
  512. },
  513. "fields" : {
  514. "@timestamp" : [
  515. "2020-06-21T20:00:01.000Z"
  516. ],
  517. "clientip" : [
  518. "211.11.9.0"
  519. ],
  520. "message" : [
  521. "211.11.9.0 - - [2020-06-21T15:00:01-05:00] \"GET /english/index.html HTTP/1.0\" 304 0"
  522. ]
  523. }
  524. }
  525. ]
  526. }
  527. }
  528. ----
  529. // TESTRESPONSE[s/\.\.\./"took" : $body.took,"timed_out" : $body.timed_out,"_shards" : $body._shards,/]
  530. // TESTRESPONSE[s/"_id" : "oWs5KXYB-XyJbifr9mrz"/"_id": $body.hits.hits.0._id/]
  531. You can add the `day_of_week` field to the mapping using the request from
  532. <<runtime-mapping-fields,mapping a runtime field>>:
  533. [source,console]
  534. ----
  535. PUT /my-index/_mapping
  536. {
  537. "runtime": {
  538. "day_of_week": {
  539. "type": "keyword",
  540. "script": {
  541. "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
  542. }
  543. }
  544. },
  545. "properties": {
  546. "timestamp": {
  547. "type": "date"
  548. }
  549. }
  550. }
  551. ----
  552. // TEST[continued]
  553. Then, you can re-run the previous search request and also retrieve the day of
  554. the week based on the `@timestamp` field:
  555. [source,console]
  556. ----
  557. GET my-index/_search
  558. {
  559. "size": 1,
  560. "query": {
  561. "match": {
  562. "clientip": "211.11.9.0"
  563. }
  564. },
  565. "fields" : ["*"]
  566. }
  567. ----
  568. // TEST[continued]
  569. The value for this field is calculated dynamically at runtime without
  570. reindexing the document or adding the `day_of_week` field. This flexibility
  571. allows you to modify the mapping without changing any field values.
  572. [source,console-result]
  573. ----
  574. {
  575. ...
  576. "hits" : {
  577. "total" : {
  578. "value" : 2,
  579. "relation" : "eq"
  580. },
  581. "max_score" : 1.0,
  582. "hits" : [
  583. {
  584. "_index" : "my-index",
  585. "_id" : "oWs5KXYB-XyJbifr9mrz",
  586. "_score" : 1.0,
  587. "_source" : {
  588. "@timestamp" : "2020-06-21T15:00:01-05:00",
  589. "message" : "211.11.9.0 - - [2020-06-21T15:00:01-05:00] \"GET /english/index.html HTTP/1.0\" 304 0"
  590. },
  591. "fields" : {
  592. "@timestamp" : [
  593. "2020-06-21T20:00:01.000Z"
  594. ],
  595. "clientip" : [
  596. "211.11.9.0"
  597. ],
  598. "message" : [
  599. "211.11.9.0 - - [2020-06-21T15:00:01-05:00] \"GET /english/index.html HTTP/1.0\" 304 0"
  600. ],
  601. "day_of_week" : [
  602. "Sunday" <1>
  603. ]
  604. }
  605. }
  606. ]
  607. }
  608. }
  609. ----
  610. // TESTRESPONSE[s/\.\.\./"took" : $body.took,"timed_out" : $body.timed_out,"_shards" : $body._shards,/]
  611. // TESTRESPONSE[s/"_id" : "oWs5KXYB-XyJbifr9mrz"/"_id": $body.hits.hits.0._id/]
  612. // TESTRESPONSE[s/"day_of_week" : \[\n\s+"Sunday"\n\s\]/"day_of_week": $body.hits.hits.0.fields.day_of_week/]
  613. <1> This value was calculated at search time using the runtime script defined
  614. in the mapping.