README.asciidoc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. The Elasticsearch docs are in AsciiDoc format and can be built using the
  2. Elasticsearch documentation build process.
  3. See: https://github.com/elastic/docs
  4. === Adding API reference pages
  5. When you need to add a reference page for a new API:
  6. * Use the API reference template:
  7. https://github.com/elastic/docs/blob/master/shared/api-ref-ex.asciidoc[template],
  8. https://www.elastic.co/guide/en/elasticsearch/reference/master/get-snapshot-repo-api.html[real-life example].
  9. * Create a separate source file for each API.
  10. * The anchor for the top-level heading should match the heading as closely as possible.
  11. * Use dashes to separate words in the anchor. (Avoid underscores.)
  12. * The name of the source file should match the anchor text.
  13. * Include an abbreviated title that drops the heading's _API_ suffix.
  14. * Start the short description with a verb.
  15. * Include the sections from the reference template as applicable.
  16. See the template for information about each section.
  17. * Add a link to the new topic from the appropriate API category page.
  18. These links are typically grouped into sub-categories and listed in logical order.
  19. For example, the put API is listed before the get and delete APIs.
  20. * Include the new file so the API appears in alphabetical order in the TOC nav.
  21. The template uses https://github.com/elastic/docs/blob/master/shared/attributes.asciidoc[shared attributes]
  22. for a number of the standard headings so we can tweak them globally if need be.
  23. Many of the API reference pages also use shared parameter definitions from
  24. https://github.com/elastic/elasticsearch/blob/master/docs/reference/rest-api/common-parms.asciidoc[elasticsearch/docs/reference/rest-api/common-parms].
  25. You don't have to do that.
  26. === Backporting doc fixes
  27. * Doc changes should generally be made against master and backported through to the current version
  28. (as applicable).
  29. * Changes can also be backported to the maintenance version of the previous major version.
  30. This is typically reserved for technical corrections, as it can require resolving more complex
  31. merge conflicts, fixing test failures, and figuring out where to apply the change.
  32. * Avoid backporting to out-of-maintenance versions.
  33. Docs follow the same policy as code and fixes are not ordinarily merged to
  34. versions that are out of maintenance.
  35. * Do not backport doc changes to https://www.elastic.co/support/eol[EOL versions].
  36. === Snippet testing
  37. Snippets marked with `[source,console]` are automatically annotated with
  38. "VIEW IN CONSOLE" and "COPY AS CURL" in the documentation and are automatically
  39. tested by the command `./gradlew -pdocs check`. To test just the docs from a
  40. single page, use e.g. `./gradlew -pdocs integTest --tests "\*rollover*"`.
  41. By default each `[source,console]` snippet runs as its own isolated test. You
  42. can manipulate the test execution in the following ways:
  43. * `// TEST`: Explicitly marks a snippet as a test. Snippets marked this way
  44. are tests even if they don't have `[source,console]` but usually `// TEST` is
  45. used for its modifiers:
  46. * `// TEST[s/foo/bar/]`: Replace `foo` with `bar` in the generated test. This
  47. should be used sparingly because it makes the snippet "lie". Sometimes,
  48. though, you can use it to make the snippet more clear. Keep in mind that
  49. if there are multiple substitutions then they are applied in the order that
  50. they are defined.
  51. * `// TEST[catch:foo]`: Used to expect errors in the requests. Replace `foo`
  52. with `request` to expect a 400 error, for example. If the snippet contains
  53. multiple requests then only the last request will expect the error.
  54. * `// TEST[continued]`: Continue the test started in the last snippet. Between
  55. tests the nodes are cleaned: indexes are removed, etc. This prevents that
  56. from happening between snippets because the two snippets are a single test.
  57. This is most useful when you have text and snippets that work together to
  58. tell the story of some use case because it merges the snippets (and thus the
  59. use case) into one big test.
  60. * You can't use `// TEST[continued]` immediately after `// TESTSETUP` or
  61. `// TEARDOWN`.
  62. * `// TEST[skip:reason]`: Skip this test. Replace `reason` with the actual
  63. reason to skip the test. Snippets without `// TEST` or `// CONSOLE` aren't
  64. considered tests anyway but this is useful for explicitly documenting the
  65. reason why the test shouldn't be run.
  66. * `// TEST[setup:name]`: Run some setup code before running the snippet. This
  67. is useful for creating and populating indexes used in the snippet. The setup
  68. code is defined in `docs/build.gradle`. See `// TESTSETUP` below for a
  69. similar feature.
  70. * `// TEST[warning:some warning]`: Expect the response to include a `Warning`
  71. header. If the response doesn't include a `Warning` header with the exact
  72. text then the test fails. If the response includes `Warning` headers that
  73. aren't expected then the test fails.
  74. * `[source,console-result]`: Matches this snippet against the body of the
  75. response of the last test. If the response is JSON then order is ignored. If
  76. you add `// TEST[continued]` to the snippet after `[source,console-result]`
  77. it will continue in the same test, allowing you to interleave requests with
  78. responses to check.
  79. * `// TESTRESPONSE`: Explicitly marks a snippet as a test response even without
  80. `[source,console-result]`. Similarly to `// TEST` this is mostly used for
  81. its modifiers.
  82. * You can't use `[source,console-result]` immediately after `// TESTSETUP`.
  83. Instead, consider using `// TEST[continued]` or rearrange your snippets.
  84. NOTE: Previously we only used `// TESTRESPONSE` instead of
  85. `[source,console-result]` so you'll see that a lot in older branches but we
  86. prefer `[source,console-result]` now.
  87. * `// TESTRESPONSE[s/foo/bar/]`: Substitutions. See `// TEST[s/foo/bar]` for
  88. how it works. These are much more common than `// TEST[s/foo/bar]` because
  89. they are useful for eliding portions of the response that are not pertinent
  90. to the documentation.
  91. * One interesting difference here is that you often want to match against
  92. the response from Elasticsearch. To do that you can reference the "body" of
  93. the response like this: `// TESTRESPONSE[s/"took": 25/"took": $body.took/]`.
  94. Note the `$body` string. This says "I don't expect that 25 number in the
  95. response, just match against what is in the response." Instead of writing
  96. the path into the response after `$body` you can write `$_path` which
  97. "figures out" the path. This is especially useful for making sweeping
  98. assertions like "I made up all the numbers in this example, don't compare
  99. them" which looks like `// TESTRESPONSE[s/\d+/$body.$_path/]`.
  100. * `// TESTRESPONSE[non_json]`: Add substitutions for testing responses in a
  101. format other than JSON. Use this after all other substitutions so it doesn't
  102. make other substitutions difficult.
  103. * `// TESTRESPONSE[skip:reason]`: Skip the assertions specified by this
  104. response.
  105. * `// TESTSETUP`: Marks this snippet as the "setup" for all other snippets in
  106. this file. This is a somewhat natural way of structuring documentation. You
  107. say "this is the data we use to explain this feature" then you add the
  108. snippet that you mark `// TESTSETUP` and then every snippet will turn into
  109. a test that runs the setup snippet first. See the "painless" docs for a file
  110. that puts this to good use. This is fairly similar to `// TEST[setup:name]`
  111. but rather than the setup defined in `docs/build.gradle` the setup is defined
  112. right in the documentation file. In general, we should prefer `// TESTSETUP`
  113. over `// TEST[setup:name]` because it makes it more clear what steps have to
  114. be taken before the examples will work. Tip: `// TESTSETUP` can only be used
  115. on the first snippet of a document.
  116. * `// TEARDOWN`: Ends and cleans up a test series started with `// TESTSETUP` or
  117. `// TEST[setup:name]`. You can use `// TEARDOWN` to set up multiple tests in
  118. the same file.
  119. * `// NOTCONSOLE`: Marks this snippet as neither `// CONSOLE` nor
  120. `// TESTRESPONSE`, excluding it from the list of unconverted snippets. We
  121. should only use this for snippets that *are* JSON but are *not* responses or
  122. requests.
  123. In addition to the standard CONSOLE syntax these snippets can contain blocks
  124. of yaml surrounded by markers like this:
  125. ```
  126. startyaml
  127. - compare_analyzers: {index: thai_example, first: thai, second: rebuilt_thai}
  128. endyaml
  129. ```
  130. This allows slightly more expressive testing of the snippets. Since that syntax
  131. is not supported by `[source,console]` the usual way to incorporate it is with a
  132. `// TEST[s//]` marker like this:
  133. ```
  134. // TEST[s/\n$/\nstartyaml\n - compare_analyzers: {index: thai_example, first: thai, second: rebuilt_thai}\nendyaml\n/]
  135. ```
  136. Any place you can use json you can use elements like `$body.path.to.thing`
  137. which is replaced on the fly with the contents of the thing at `path.to.thing`
  138. in the last response.