usage.asciidoc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[java-rest-high-usage]]
  2. === Getting started
  3. [[java-rest-high-usage-maven]]
  4. ==== Maven Repository
  5. The high-level Java REST client is hosted on
  6. http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.elasticsearch.client%22[Maven
  7. Central]. The minimum Java version required is `1.8`.
  8. The high-level REST client is subject to the same release cycle as
  9. elasticsearch. Replace the version with the desired client version, first
  10. released with `5.x.x`. There is no relation between the client version
  11. and the elasticsearch version that the client can communicate with as
  12. it depends on the <<java-rest-low>> which is compatible with all elasticsearch versions.
  13. [[java-rest-high-usage-maven-maven]]
  14. ===== Maven configuration
  15. Here is how you can configure the dependency using maven as a dependency manager.
  16. Add the following to your `pom.xml` file:
  17. ["source","xml",subs="attributes"]
  18. --------------------------------------------------
  19. <dependency>
  20. <groupId>org.elasticsearch.client</groupId>
  21. <artifactId>rest-high-level</artifactId>
  22. <version>{version}</version>
  23. </dependency>
  24. --------------------------------------------------
  25. [[java-rest-high-usage-maven-gradle]]
  26. ===== Gradle configuration
  27. Here is how you can configure the dependency using gradle as a dependency manager.
  28. Add the following to your `build.gradle` file:
  29. ["source","groovy",subs="attributes"]
  30. --------------------------------------------------
  31. dependencies {
  32. compile 'org.elasticsearch.client:rest-high-level:{version}'
  33. }
  34. --------------------------------------------------
  35. [[java-rest-high-usage-dependencies]]
  36. ==== Dependencies
  37. The high-level Java REST client depends on the following artifacts and their
  38. transitive dependencies:
  39. - org.elasticsearch.client:rest
  40. - org.elasticsearch:elasticsearch
  41. [[java-rest-high-usage-initialization]]
  42. ==== Initialization
  43. A `RestHighLevelClient` instance needs a <<java-rest-low-usage-initialization,REST low-level client>>
  44. to be built as follows:
  45. [source,java]
  46. --------------------------------------------------
  47. RestHighLevelClient client =
  48. new RestHighLevelClient(lowLevelRestClient); <1>
  49. --------------------------------------------------
  50. <1> We pass the <<java-rest-low-usage-initialization,REST low-level client>> instance
  51. In the rest of this documentation about the high-level client, the `RestHighLevelClient` instance
  52. will be referenced as `client`.
  53. Then you have access to the high level APIs such as:
  54. include::apis.asciidoc[]
  55. Each API comes with 2 ways of executing it:
  56. * Synchronously, for example method <<java-rest-high-document-delete,`delete`>>
  57. * Asynchronously which has `Async` added to the synchronous method name. Like
  58. <<java-rest-high-document-delete,`deleteAsync`>>. In which case you will have to
  59. provide a listener.