index.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. [[java-api]]
  2. = Java API
  3. include::../Versions.asciidoc[]
  4. [preface]
  5. == Preface
  6. deprecated[7.0.0, The `TransportClient` is deprecated in favour of the {java-rest}/java-rest-high.html[Java High Level REST Client] and will be removed in Elasticsearch 8.0. The {java-rest}/java-rest-high-level-migration.html[migration guide] describes all the steps needed to migrate.]
  7. This section describes the Java API that Elasticsearch provides. All
  8. Elasticsearch operations are executed using a
  9. <<client,Client>> object. All
  10. operations are completely asynchronous in nature (either accepts a
  11. listener, or returns a future).
  12. Additionally, operations on a client may be accumulated and executed in
  13. <<java-docs-bulk,Bulk>>.
  14. Note, all the APIs are exposed through the
  15. Java API (actually, the Java API is used internally to execute them).
  16. == Javadoc
  17. The javadoc for the transport client can be found at {transport-client-javadoc}/index.html.
  18. == Maven Repository
  19. Elasticsearch is hosted on
  20. http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22elasticsearch%22[Maven
  21. Central].
  22. For example, you can define the latest version in your `pom.xml` file:
  23. ["source","xml",subs="attributes"]
  24. --------------------------------------------------
  25. <dependency>
  26. <groupId>org.elasticsearch.client</groupId>
  27. <artifactId>transport</artifactId>
  28. <version>{version}</version>
  29. </dependency>
  30. --------------------------------------------------
  31. [[java-transport-usage-maven-lucene]]
  32. === Lucene Snapshot repository
  33. The very first releases of any major version (like a beta), might have been built on top of a Lucene Snapshot version.
  34. In such a case you will be unable to resolve the Lucene dependencies of the client.
  35. For example, if you want to use the `6.0.0-beta1` version which depends on Lucene `7.0.0-snapshot-00142c9`, you must
  36. define the following repository.
  37. For Maven:
  38. ["source","xml",subs="attributes"]
  39. --------------------------------------------------
  40. <repository>
  41. <id>elastic-lucene-snapshots</id>
  42. <name>Elastic Lucene Snapshots</name>
  43. <url>http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
  44. <releases><enabled>true</enabled></releases>
  45. <snapshots><enabled>false</enabled></snapshots>
  46. </repository>
  47. --------------------------------------------------
  48. For Gradle:
  49. ["source","groovy",subs="attributes"]
  50. --------------------------------------------------
  51. maven {
  52. url 'http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9'
  53. }
  54. --------------------------------------------------
  55. === Log4j 2 Logger
  56. You need to also include Log4j 2 dependencies:
  57. ["source","xml",subs="attributes"]
  58. --------------------------------------------------
  59. <dependency>
  60. <groupId>org.apache.logging.log4j</groupId>
  61. <artifactId>log4j-core</artifactId>
  62. <version>2.9.1</version>
  63. </dependency>
  64. --------------------------------------------------
  65. And also provide a Log4j 2 configuration file in your classpath.
  66. For example, you can add in your `src/main/resources` project dir a `log4j2.properties` file like:
  67. ["source","properties",subs="attributes"]
  68. --------------------------------------------------
  69. appender.console.type = Console
  70. appender.console.name = console
  71. appender.console.layout.type = PatternLayout
  72. appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%m%n
  73. rootLogger.level = info
  74. rootLogger.appenderRef.console.ref = console
  75. --------------------------------------------------
  76. === Using another Logger
  77. If you want to use another logger than Log4j 2, you can use http://www.slf4j.org/[SLF4J] bridge to do that:
  78. ["source","xml",subs="attributes"]
  79. --------------------------------------------------
  80. <dependency>
  81. <groupId>org.apache.logging.log4j</groupId>
  82. <artifactId>log4j-to-slf4j</artifactId>
  83. <version>2.9.1</version>
  84. </dependency>
  85. <dependency>
  86. <groupId>org.slf4j</groupId>
  87. <artifactId>slf4j-api</artifactId>
  88. <version>1.7.24</version>
  89. </dependency>
  90. --------------------------------------------------
  91. http://www.slf4j.org/manual.html[This page] lists implementations you can use. Pick your favorite logger
  92. and add it as a dependency. As an example, we will use the `slf4j-simple` logger:
  93. ["source","xml",subs="attributes"]
  94. --------------------------------------------------
  95. <dependency>
  96. <groupId>org.slf4j</groupId>
  97. <artifactId>slf4j-simple</artifactId>
  98. <version>1.7.21</version>
  99. </dependency>
  100. --------------------------------------------------
  101. :client-tests: {docdir}/../../server/src/test/java/org/elasticsearch/client/documentation
  102. :client-reindex-tests: {docdir}/../../modules/reindex/src/test/java/org/elasticsearch/client/documentation
  103. include::client.asciidoc[]
  104. include::docs.asciidoc[]
  105. include::search.asciidoc[]
  106. include::aggs.asciidoc[]
  107. include::query-dsl.asciidoc[]
  108. include::admin/index.asciidoc[]