update-by-query.asciidoc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. [[docs-update-by-query]]
  2. == Update By Query API
  3. The simplest usage of `_update_by_query` just performs an update on every
  4. document in the index without changing the source. This is useful to
  5. <<picking-up-a-new-property,pick up a new property>> or some other online
  6. mapping change. Here is the API:
  7. [source,js]
  8. --------------------------------------------------
  9. POST twitter/_update_by_query?conflicts=proceed
  10. --------------------------------------------------
  11. // CONSOLE
  12. // TEST[setup:big_twitter]
  13. That will return something like this:
  14. [source,js]
  15. --------------------------------------------------
  16. {
  17. "took" : 147,
  18. "timed_out": false,
  19. "updated": 120,
  20. "deleted": 0,
  21. "batches": 1,
  22. "version_conflicts": 0,
  23. "noops": 0,
  24. "retries": {
  25. "bulk": 0,
  26. "search": 0
  27. },
  28. "throttled_millis": 0,
  29. "requests_per_second": -1.0,
  30. "throttled_until_millis": 0,
  31. "total": 120,
  32. "failures" : [ ]
  33. }
  34. --------------------------------------------------
  35. // TESTRESPONSE[s/"took" : 147/"took" : "$body.took"/]
  36. `_update_by_query` gets a snapshot of the index when it starts and indexes what
  37. it finds using `internal` versioning. That means that you'll get a version
  38. conflict if the document changes between the time when the snapshot was taken
  39. and when the index request is processed. When the versions match the document
  40. is updated and the version number is incremented.
  41. NOTE: Since `internal` versioning does not support the value 0 as a valid
  42. version number, documents with version equal to zero cannot be updated using
  43. `_update_by_query` and will fail the request.
  44. All update and query failures cause the `_update_by_query` to abort and are
  45. returned in the `failures` of the response. The updates that have been
  46. performed still stick. In other words, the process is not rolled back, only
  47. aborted. While the first failure causes the abort, all failures that are
  48. returned by the failing bulk request are returned in the `failures` element; therefore
  49. it's possible for there to be quite a few failed entities.
  50. If you want to simply count version conflicts not cause the `_update_by_query`
  51. to abort you can set `conflicts=proceed` on the url or `"conflicts": "proceed"`
  52. in the request body. The first example does this because it is just trying to
  53. pick up an online mapping change and a version conflict simply means that the
  54. conflicting document was updated between the start of the `_update_by_query`
  55. and the time when it attempted to update the document. This is fine because
  56. that update will have picked up the online mapping update.
  57. Back to the API format, this will update tweets from the `twitter` index:
  58. [source,js]
  59. --------------------------------------------------
  60. POST twitter/_update_by_query?conflicts=proceed
  61. --------------------------------------------------
  62. // CONSOLE
  63. // TEST[setup:twitter]
  64. You can also limit `_update_by_query` using the
  65. <<query-dsl,Query DSL>>. This will update all documents from the
  66. `twitter` index for the user `kimchy`:
  67. [source,js]
  68. --------------------------------------------------
  69. POST twitter/_update_by_query?conflicts=proceed
  70. {
  71. "query": { <1>
  72. "term": {
  73. "user": "kimchy"
  74. }
  75. }
  76. }
  77. --------------------------------------------------
  78. // CONSOLE
  79. // TEST[setup:twitter]
  80. <1> The query must be passed as a value to the `query` key, in the same
  81. way as the <<search-search,Search API>>. You can also use the `q`
  82. parameter in the same way as the search api.
  83. So far we've only been updating documents without changing their source. That
  84. is genuinely useful for things like
  85. <<picking-up-a-new-property,picking up new properties>> but it's only half the
  86. fun. `_update_by_query` <<modules-scripting-using,supports scripts>> to update
  87. the document. This will increment the `likes` field on all of kimchy's tweets:
  88. [source,js]
  89. --------------------------------------------------
  90. POST twitter/_update_by_query
  91. {
  92. "script": {
  93. "source": "ctx._source.likes++",
  94. "lang": "painless"
  95. },
  96. "query": {
  97. "term": {
  98. "user": "kimchy"
  99. }
  100. }
  101. }
  102. --------------------------------------------------
  103. // CONSOLE
  104. // TEST[setup:twitter]
  105. Just as in <<docs-update,Update API>> you can set `ctx.op` to change the
  106. operation that is executed:
  107. `noop`::
  108. Set `ctx.op = "noop"` if your script decides that it doesn't have to make any
  109. changes. That will cause `_update_by_query` to omit that document from its updates.
  110. This no operation will be reported in the `noop` counter in the
  111. <<docs-update-by-query-response-body, response body>>.
  112. `delete`::
  113. Set `ctx.op = "delete"` if your script decides that the document must be
  114. deleted. The deletion will be reported in the `deleted` counter in the
  115. <<docs-update-by-query-response-body, response body>>.
  116. Setting `ctx.op` to anything else is an error. Setting any
  117. other field in `ctx` is an error.
  118. Note that we stopped specifying `conflicts=proceed`. In this case we want a
  119. version conflict to abort the process so we can handle the failure.
  120. This API doesn't allow you to move the documents it touches, just modify their
  121. source. This is intentional! We've made no provisions for removing the document
  122. from its original location.
  123. It's also possible to do this whole thing on multiple indexes at once, just
  124. like the search API:
  125. [source,js]
  126. --------------------------------------------------
  127. POST twitter,blog/_update_by_query
  128. --------------------------------------------------
  129. // CONSOLE
  130. // TEST[s/^/PUT twitter\nPUT blog\n/]
  131. If you provide `routing` then the routing is copied to the scroll query,
  132. limiting the process to the shards that match that routing value:
  133. [source,js]
  134. --------------------------------------------------
  135. POST twitter/_update_by_query?routing=1
  136. --------------------------------------------------
  137. // CONSOLE
  138. // TEST[setup:twitter]
  139. By default `_update_by_query` uses scroll batches of 1000. You can change the
  140. batch size with the `scroll_size` URL parameter:
  141. [source,js]
  142. --------------------------------------------------
  143. POST twitter/_update_by_query?scroll_size=100
  144. --------------------------------------------------
  145. // CONSOLE
  146. // TEST[setup:twitter]
  147. `_update_by_query` can also use the <<ingest>> feature by
  148. specifying a `pipeline` like this:
  149. [source,js]
  150. --------------------------------------------------
  151. PUT _ingest/pipeline/set-foo
  152. {
  153. "description" : "sets foo",
  154. "processors" : [ {
  155. "set" : {
  156. "field": "foo",
  157. "value": "bar"
  158. }
  159. } ]
  160. }
  161. POST twitter/_update_by_query?pipeline=set-foo
  162. --------------------------------------------------
  163. // CONSOLE
  164. // TEST[setup:twitter]
  165. [float]
  166. === URL Parameters
  167. In addition to the standard parameters like `pretty`, the Update By Query API
  168. also supports `refresh`, `wait_for_completion`, `wait_for_active_shards`, `timeout`
  169. and `scroll`.
  170. Sending the `refresh` will update all shards in the index being updated when
  171. the request completes. This is different than the Update API's `refresh`
  172. parameter which causes just the shard that received the new data to be indexed.
  173. Also unlike the Update API it does not support `wait_for`.
  174. If the request contains `wait_for_completion=false` then Elasticsearch will
  175. perform some preflight checks, launch the request, and then return a `task`
  176. which can be used with <<docs-update-by-query-task-api,Tasks APIs>>
  177. to cancel or get the status of the task. Elasticsearch will also create a
  178. record of this task as a document at `.tasks/task/${taskId}`. This is yours
  179. to keep or remove as you see fit. When you are done with it, delete it so
  180. Elasticsearch can reclaim the space it uses.
  181. `wait_for_active_shards` controls how many copies of a shard must be active
  182. before proceeding with the request. See <<index-wait-for-active-shards,here>>
  183. for details. `timeout` controls how long each write request waits for unavailable
  184. shards to become available. Both work exactly how they work in the
  185. <<docs-bulk,Bulk API>>. As `_update_by_query` uses scroll search, you can also specify
  186. the `scroll` parameter to control how long it keeps the "search context" alive,
  187. eg `?scroll=10m`, by default it's 5 minutes.
  188. `requests_per_second` can be set to any positive decimal number (`1.4`, `6`,
  189. `1000`, etc) and throttles rate at which `_update_by_query` issues batches of
  190. index operations by padding each batch with a wait time. The throttling can be
  191. disabled by setting `requests_per_second` to `-1`.
  192. The throttling is done by waiting between batches so that scroll that
  193. `_update_by_query` uses internally can be given a timeout that takes into
  194. account the padding. The padding time is the difference between the batch size
  195. divided by the `requests_per_second` and the time spent writing. By default the
  196. batch size is `1000`, so if the `requests_per_second` is set to `500`:
  197. [source,txt]
  198. --------------------------------------------------
  199. target_time = 1000 / 500 per second = 2 seconds
  200. wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds
  201. --------------------------------------------------
  202. Since the batch is issued as a single `_bulk` request large batch sizes will
  203. cause Elasticsearch to create many requests and then wait for a while before
  204. starting the next set. This is "bursty" instead of "smooth". The default is `-1`.
  205. [float]
  206. [[docs-update-by-query-response-body]]
  207. === Response body
  208. //////////////////////////
  209. [source,js]
  210. --------------------------------------------------
  211. POST /twitter/_update_by_query?conflicts=proceed
  212. --------------------------------------------------
  213. // CONSOLE
  214. // TEST[setup:twitter]
  215. //////////////////////////
  216. The JSON response looks like this:
  217. [source,js]
  218. --------------------------------------------------
  219. {
  220. "took" : 147,
  221. "timed_out": false,
  222. "total": 5,
  223. "updated": 5,
  224. "deleted": 0,
  225. "batches": 1,
  226. "version_conflicts": 0,
  227. "noops": 0,
  228. "retries": {
  229. "bulk": 0,
  230. "search": 0
  231. },
  232. "throttled_millis": 0,
  233. "requests_per_second": -1.0,
  234. "throttled_until_millis": 0,
  235. "failures" : [ ]
  236. }
  237. --------------------------------------------------
  238. // TESTRESPONSE[s/"took" : 147/"took" : "$body.took"/]
  239. `took`::
  240. The number of milliseconds from start to end of the whole operation.
  241. `timed_out`::
  242. This flag is set to `true` if any of the requests executed during the
  243. update by query execution has timed out.
  244. `total`::
  245. The number of documents that were successfully processed.
  246. `updated`::
  247. The number of documents that were successfully updated.
  248. `deleted`::
  249. The number of documents that were successfully deleted.
  250. `batches`::
  251. The number of scroll responses pulled back by the update by query.
  252. `version_conflicts`::
  253. The number of version conflicts that the update by query hit.
  254. `noops`::
  255. The number of documents that were ignored because the script used for
  256. the update by query returned a `noop` value for `ctx.op`.
  257. `retries`::
  258. The number of retries attempted by update-by-query. `bulk` is the number of bulk
  259. actions retried and `search` is the number of search actions retried.
  260. `throttled_millis`::
  261. Number of milliseconds the request slept to conform to `requests_per_second`.
  262. `requests_per_second`::
  263. The number of requests per second effectively executed during the update by query.
  264. `throttled_until_millis`::
  265. This field should always be equal to zero in an `_update_by_query` response. It only
  266. has meaning when using the <<docs-update-by-query-task-api, Task API>>, where it
  267. indicates the next time (in milliseconds since epoch) a throttled request will be
  268. executed again in order to conform to `requests_per_second`.
  269. `failures`::
  270. Array of failures if there were any unrecoverable errors during the process. If
  271. this is non-empty then the request aborted because of those failures.
  272. Update-by-query is implemented using batches and any failure causes the entire
  273. process to abort but all failures in the current batch are collected into the
  274. array. You can use the `conflicts` option to prevent reindex from aborting on
  275. version conflicts.
  276. [float]
  277. [[docs-update-by-query-task-api]]
  278. === Works with the Task API
  279. You can fetch the status of all running update-by-query requests with the
  280. <<tasks,Task API>>:
  281. [source,js]
  282. --------------------------------------------------
  283. GET _tasks?detailed=true&actions=*byquery
  284. --------------------------------------------------
  285. // CONSOLE
  286. // TEST[skip:No tasks to retrieve]
  287. The responses looks like:
  288. [source,js]
  289. --------------------------------------------------
  290. {
  291. "nodes" : {
  292. "r1A2WoRbTwKZ516z6NEs5A" : {
  293. "name" : "r1A2WoR",
  294. "transport_address" : "127.0.0.1:9300",
  295. "host" : "127.0.0.1",
  296. "ip" : "127.0.0.1:9300",
  297. "attributes" : {
  298. "testattr" : "test",
  299. "portsfile" : "true"
  300. },
  301. "tasks" : {
  302. "r1A2WoRbTwKZ516z6NEs5A:36619" : {
  303. "node" : "r1A2WoRbTwKZ516z6NEs5A",
  304. "id" : 36619,
  305. "type" : "transport",
  306. "action" : "indices:data/write/update/byquery",
  307. "status" : { <1>
  308. "total" : 6154,
  309. "updated" : 3500,
  310. "created" : 0,
  311. "deleted" : 0,
  312. "batches" : 4,
  313. "version_conflicts" : 0,
  314. "noops" : 0,
  315. "retries": {
  316. "bulk": 0,
  317. "search": 0
  318. },
  319. "throttled_millis": 0
  320. },
  321. "description" : ""
  322. }
  323. }
  324. }
  325. }
  326. }
  327. --------------------------------------------------
  328. // TESTRESPONSE
  329. <1> this object contains the actual status. It is just like the response json
  330. with the important addition of the `total` field. `total` is the total number
  331. of operations that the reindex expects to perform. You can estimate the
  332. progress by adding the `updated`, `created`, and `deleted` fields. The request
  333. will finish when their sum is equal to the `total` field.
  334. With the task id you can look up the task directly. The following example
  335. retrieves information about task `r1A2WoRbTwKZ516z6NEs5A:36619`:
  336. [source,js]
  337. --------------------------------------------------
  338. GET /_tasks/r1A2WoRbTwKZ516z6NEs5A:36619
  339. --------------------------------------------------
  340. // CONSOLE
  341. // TEST[catch:missing]
  342. The advantage of this API is that it integrates with `wait_for_completion=false`
  343. to transparently return the status of completed tasks. If the task is completed
  344. and `wait_for_completion=false` was set on it them it'll come back with a
  345. `results` or an `error` field. The cost of this feature is the document that
  346. `wait_for_completion=false` creates at `.tasks/task/${taskId}`. It is up to
  347. you to delete that document.
  348. [float]
  349. [[docs-update-by-query-cancel-task-api]]
  350. === Works with the Cancel Task API
  351. Any Update By Query can be canceled using the <<tasks,Task Cancel API>>:
  352. [source,js]
  353. --------------------------------------------------
  354. POST _tasks/r1A2WoRbTwKZ516z6NEs5A:36619/_cancel
  355. --------------------------------------------------
  356. // CONSOLE
  357. The task ID can be found using the <<tasks,tasks API>>.
  358. Cancellation should happen quickly but might take a few seconds. The task status
  359. API above will continue to list the task until it is wakes to cancel itself.
  360. [float]
  361. [[docs-update-by-query-rethrottle]]
  362. === Rethrottling
  363. The value of `requests_per_second` can be changed on a running update by query
  364. using the `_rethrottle` API:
  365. [source,js]
  366. --------------------------------------------------
  367. POST _update_by_query/r1A2WoRbTwKZ516z6NEs5A:36619/_rethrottle?requests_per_second=-1
  368. --------------------------------------------------
  369. // CONSOLE
  370. The task ID can be found using the <<tasks, tasks API>>.
  371. Just like when setting it on the `_update_by_query` API `requests_per_second`
  372. can be either `-1` to disable throttling or any decimal number
  373. like `1.7` or `12` to throttle to that level. Rethrottling that speeds up the
  374. query takes effect immediately but rethrotting that slows down the query will
  375. take effect on after completing the current batch. This prevents scroll
  376. timeouts.
  377. [float]
  378. [[docs-update-by-query-slice]]
  379. === Slicing
  380. Update-by-query supports <<sliced-scroll>> to parallelize the updating process.
  381. This parallelization can improve efficiency and provide a convenient way to
  382. break the request down into smaller parts.
  383. [float]
  384. [[docs-update-by-query-manual-slice]]
  385. ==== Manual slicing
  386. Slice an update-by-query manually by providing a slice id and total number of
  387. slices to each request:
  388. [source,js]
  389. ----------------------------------------------------------------
  390. POST twitter/_update_by_query
  391. {
  392. "slice": {
  393. "id": 0,
  394. "max": 2
  395. },
  396. "script": {
  397. "source": "ctx._source['extra'] = 'test'"
  398. }
  399. }
  400. POST twitter/_update_by_query
  401. {
  402. "slice": {
  403. "id": 1,
  404. "max": 2
  405. },
  406. "script": {
  407. "source": "ctx._source['extra'] = 'test'"
  408. }
  409. }
  410. ----------------------------------------------------------------
  411. // CONSOLE
  412. // TEST[setup:big_twitter]
  413. Which you can verify works with:
  414. [source,js]
  415. ----------------------------------------------------------------
  416. GET _refresh
  417. POST twitter/_search?size=0&q=extra:test&filter_path=hits.total
  418. ----------------------------------------------------------------
  419. // CONSOLE
  420. // TEST[continued]
  421. Which results in a sensible `total` like this one:
  422. [source,js]
  423. ----------------------------------------------------------------
  424. {
  425. "hits": {
  426. "total": {
  427. "value": 120,
  428. "relation": "eq"
  429. }
  430. }
  431. }
  432. ----------------------------------------------------------------
  433. // TESTRESPONSE
  434. [float]
  435. [[docs-update-by-query-automatic-slice]]
  436. ==== Automatic slicing
  437. You can also let update-by-query automatically parallelize using
  438. <<sliced-scroll>> to slice on `_id`. Use `slices` to specify the number of
  439. slices to use:
  440. [source,js]
  441. ----------------------------------------------------------------
  442. POST twitter/_update_by_query?refresh&slices=5
  443. {
  444. "script": {
  445. "source": "ctx._source['extra'] = 'test'"
  446. }
  447. }
  448. ----------------------------------------------------------------
  449. // CONSOLE
  450. // TEST[setup:big_twitter]
  451. Which you also can verify works with:
  452. [source,js]
  453. ----------------------------------------------------------------
  454. POST twitter/_search?size=0&q=extra:test&filter_path=hits.total
  455. ----------------------------------------------------------------
  456. // CONSOLE
  457. // TEST[continued]
  458. Which results in a sensible `total` like this one:
  459. [source,js]
  460. ----------------------------------------------------------------
  461. {
  462. "hits": {
  463. "total": {
  464. "value": 120,
  465. "relation": "eq"
  466. }
  467. }
  468. }
  469. ----------------------------------------------------------------
  470. // TESTRESPONSE
  471. Setting `slices` to `auto` will let Elasticsearch choose the number of slices
  472. to use. This setting will use one slice per shard, up to a certain limit. If
  473. there are multiple source indices, it will choose the number of slices based
  474. on the index with the smallest number of shards.
  475. Adding `slices` to `_update_by_query` just automates the manual process used in
  476. the section above, creating sub-requests which means it has some quirks:
  477. * You can see these requests in the
  478. <<docs-update-by-query-task-api,Tasks APIs>>. These sub-requests are "child"
  479. tasks of the task for the request with `slices`.
  480. * Fetching the status of the task for the request with `slices` only contains
  481. the status of completed slices.
  482. * These sub-requests are individually addressable for things like cancellation
  483. and rethrottling.
  484. * Rethrottling the request with `slices` will rethrottle the unfinished
  485. sub-request proportionally.
  486. * Canceling the request with `slices` will cancel each sub-request.
  487. * Due to the nature of `slices` each sub-request won't get a perfectly even
  488. portion of the documents. All documents will be addressed, but some slices may
  489. be larger than others. Expect larger slices to have a more even distribution.
  490. * Parameters like `requests_per_second` and `size` on a request with `slices`
  491. are distributed proportionally to each sub-request. Combine that with the point
  492. above about distribution being uneven and you should conclude that the using
  493. `size` with `slices` might not result in exactly `size` documents being
  494. `_update_by_query`ed.
  495. * Each sub-requests gets a slightly different snapshot of the source index
  496. though these are all taken at approximately the same time.
  497. [float]
  498. [[docs-update-by-query-picking-slices]]
  499. ===== Picking the number of slices
  500. If slicing automatically, setting `slices` to `auto` will choose a reasonable
  501. number for most indices. If you're slicing manually or otherwise tuning
  502. automatic slicing, use these guidelines.
  503. Query performance is most efficient when the number of `slices` is equal to the
  504. number of shards in the index. If that number is large, (for example,
  505. 500) choose a lower number as too many `slices` will hurt performance. Setting
  506. `slices` higher than the number of shards generally does not improve efficiency
  507. and adds overhead.
  508. Update performance scales linearly across available resources with the
  509. number of slices.
  510. Whether query or update performance dominates the runtime depends on the
  511. documents being reindexed and cluster resources.
  512. [float]
  513. [[picking-up-a-new-property]]
  514. === Pick up a new property
  515. Say you created an index without dynamic mapping, filled it with data, and then
  516. added a mapping value to pick up more fields from the data:
  517. [source,js]
  518. --------------------------------------------------
  519. PUT test
  520. {
  521. "mappings": {
  522. "_doc": {
  523. "dynamic": false, <1>
  524. "properties": {
  525. "text": {"type": "text"}
  526. }
  527. }
  528. }
  529. }
  530. POST test/_doc?refresh
  531. {
  532. "text": "words words",
  533. "flag": "bar"
  534. }
  535. POST test/_doc?refresh
  536. {
  537. "text": "words words",
  538. "flag": "foo"
  539. }
  540. PUT test/_mapping/_doc <2>
  541. {
  542. "properties": {
  543. "text": {"type": "text"},
  544. "flag": {"type": "text", "analyzer": "keyword"}
  545. }
  546. }
  547. --------------------------------------------------
  548. // CONSOLE
  549. <1> This means that new fields won't be indexed, just stored in `_source`.
  550. <2> This updates the mapping to add the new `flag` field. To pick up the new
  551. field you have to reindex all documents with it.
  552. Searching for the data won't find anything:
  553. [source,js]
  554. --------------------------------------------------
  555. POST test/_search?filter_path=hits.total
  556. {
  557. "query": {
  558. "match": {
  559. "flag": "foo"
  560. }
  561. }
  562. }
  563. --------------------------------------------------
  564. // CONSOLE
  565. // TEST[continued]
  566. [source,js]
  567. --------------------------------------------------
  568. {
  569. "hits" : {
  570. "total": {
  571. "value": 0,
  572. "relation": "eq"
  573. }
  574. }
  575. }
  576. --------------------------------------------------
  577. // TESTRESPONSE
  578. But you can issue an `_update_by_query` request to pick up the new mapping:
  579. [source,js]
  580. --------------------------------------------------
  581. POST test/_update_by_query?refresh&conflicts=proceed
  582. POST test/_search?filter_path=hits.total
  583. {
  584. "query": {
  585. "match": {
  586. "flag": "foo"
  587. }
  588. }
  589. }
  590. --------------------------------------------------
  591. // CONSOLE
  592. // TEST[continued]
  593. [source,js]
  594. --------------------------------------------------
  595. {
  596. "hits" : {
  597. "total": {
  598. "value": 1,
  599. "relation": "eq"
  600. }
  601. }
  602. }
  603. --------------------------------------------------
  604. // TESTRESPONSE
  605. You can do the exact same thing when adding a field to a multifield.