index.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. --
  2. :api: index
  3. :request: IndexRequest
  4. :response: IndexResponse
  5. --
  6. [id="{upid}-{api}"]
  7. === Index API
  8. [id="{upid}-{api}-request"]
  9. ==== Index Request
  10. An +{request}+ requires the following arguments:
  11. ["source","java",subs="attributes,callouts,macros"]
  12. --------------------------------------------------
  13. include-tagged::{doc-tests-file}[{api}-request-string]
  14. --------------------------------------------------
  15. <1> Index
  16. <2> Document id for the request
  17. <3> Document source provided as a `String`
  18. ==== Providing the document source
  19. The document source can be provided in different ways in addition to the
  20. `String` example shown above:
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{doc-tests-file}[{api}-request-map]
  24. --------------------------------------------------
  25. <1> Document source provided as a `Map` which gets automatically converted
  26. to JSON format
  27. ["source","java",subs="attributes,callouts,macros"]
  28. --------------------------------------------------
  29. include-tagged::{doc-tests-file}[{api}-request-xcontent]
  30. --------------------------------------------------
  31. <1> Document source provided as an `XContentBuilder` object, the Elasticsearch
  32. built-in helpers to generate JSON content
  33. ["source","java",subs="attributes,callouts,macros"]
  34. --------------------------------------------------
  35. include-tagged::{doc-tests-file}[{api}-request-shortcut]
  36. --------------------------------------------------
  37. <1> Document source provided as `Object` key-pairs, which gets converted to
  38. JSON format
  39. ==== Optional arguments
  40. The following arguments can optionally be provided:
  41. ["source","java",subs="attributes,callouts,macros"]
  42. --------------------------------------------------
  43. include-tagged::{doc-tests-file}[{api}-request-routing]
  44. --------------------------------------------------
  45. <1> Routing value
  46. ["source","java",subs="attributes,callouts,macros"]
  47. --------------------------------------------------
  48. include-tagged::{doc-tests-file}[{api}-request-timeout]
  49. --------------------------------------------------
  50. <1> Timeout to wait for primary shard to become available as a `TimeValue`
  51. <2> Timeout to wait for primary shard to become available as a `String`
  52. ["source","java",subs="attributes,callouts,macros"]
  53. --------------------------------------------------
  54. include-tagged::{doc-tests-file}[{api}-request-refresh]
  55. --------------------------------------------------
  56. <1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
  57. <2> Refresh policy as a `String`
  58. ["source","java",subs="attributes,callouts,macros"]
  59. --------------------------------------------------
  60. include-tagged::{doc-tests-file}[{api}-request-version]
  61. --------------------------------------------------
  62. <1> Version
  63. ["source","java",subs="attributes,callouts,macros"]
  64. --------------------------------------------------
  65. include-tagged::{doc-tests-file}[{api}-request-version-type]
  66. --------------------------------------------------
  67. <1> Version type
  68. ["source","java",subs="attributes,callouts,macros"]
  69. --------------------------------------------------
  70. include-tagged::{doc-tests-file}[{api}-request-op-type]
  71. --------------------------------------------------
  72. <1> Operation type provided as an `DocWriteRequest.OpType` value
  73. <2> Operation type provided as a `String`: can be `create` or `update` (default)
  74. ["source","java",subs="attributes,callouts,macros"]
  75. --------------------------------------------------
  76. include-tagged::{doc-tests-file}[{api}-request-pipeline]
  77. --------------------------------------------------
  78. <1> The name of the ingest pipeline to be executed before indexing the document
  79. include::../execution.asciidoc[]
  80. [id="{upid}-{api}-response"]
  81. ==== Index Response
  82. The returned +{response}+ allows to retrieve information about the executed
  83. operation as follows:
  84. ["source","java",subs="attributes,callouts,macros"]
  85. --------------------------------------------------
  86. include-tagged::{doc-tests-file}[{api}-response]
  87. --------------------------------------------------
  88. <1> Handle (if needed) the case where the document was created for the first
  89. time
  90. <2> Handle (if needed) the case where the document was rewritten as it was
  91. already existing
  92. <3> Handle the situation where number of successful shards is less than
  93. total shards
  94. <4> Handle the potential failures
  95. If there is a version conflict, an `ElasticsearchException` will
  96. be thrown:
  97. ["source","java",subs="attributes,callouts,macros"]
  98. --------------------------------------------------
  99. include-tagged::{doc-tests-file}[{api}-conflict]
  100. --------------------------------------------------
  101. <1> The raised exception indicates that a version conflict error was returned
  102. Same will happen in case `opType` was set to `create` and a document with
  103. same index and id already existed:
  104. ["source","java",subs="attributes,callouts,macros"]
  105. --------------------------------------------------
  106. include-tagged::{doc-tests-file}[{api}-optype]
  107. --------------------------------------------------
  108. <1> The raised exception indicates that a version conflict error was returned