index.asciidoc 4.9 KB

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