index.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. [[java-api]]
  2. = Java API
  3. :ref: http://www.elastic.co/guide/en/elasticsearch/reference/master
  4. :version: 5.0.0-alpha5
  5. [preface]
  6. == Preface
  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. == Maven Repository
  17. Elasticsearch is hosted on
  18. http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22elasticsearch%22[Maven
  19. Central].
  20. For example, you can define the latest version in your `pom.xml` file:
  21. ["source","xml",subs="attributes"]
  22. --------------------------------------------------
  23. <dependency>
  24. <groupId>org.elasticsearch.client</groupId>
  25. <artifactId>transport</artifactId>
  26. <version>{version}</version>
  27. </dependency>
  28. --------------------------------------------------
  29. == Dealing with JAR dependency conflicts
  30. If you want to use Elasticsearch in your Java application, you may have to deal with version conflicts with third party
  31. dependencies like Guava and Joda. For instance, perhaps Elasticsearch uses Joda 2.8, while your code uses Joda 2.1.
  32. You have two choices:
  33. * The simplest solution is to upgrade. Newer module versions are likely to have fixed old bugs.
  34. The further behind you fall, the harder it will be to upgrade later. Of course, it is possible that you are using a
  35. third party dependency that in turn depends on an outdated version of a package, which prevents you from upgrading.
  36. * The second option is to relocate the troublesome dependencies and to shade them either with your own application
  37. or with Elasticsearch and any plugins needed by the Elasticsearch client.
  38. The https://www.elastic.co/blog/to-shade-or-not-to-shade["To shade or not to shade" blog post] describes
  39. all the steps for doing so.
  40. == Embedding jar with dependencies
  41. If you want to create a single jar containing your application and all dependencies, you should not
  42. use `maven-assembly-plugin` for that because it can not deal with `META-INF/services` structure which is
  43. required by Lucene jars.
  44. Instead, you can use `maven-shade-plugin` and configure it as follow:
  45. [source,xml]
  46. --------------------------------------------------
  47. <plugin>
  48. <groupId>org.apache.maven.plugins</groupId>
  49. <artifactId>maven-shade-plugin</artifactId>
  50. <version>2.4.1</version>
  51. <executions>
  52. <execution>
  53. <phase>package</phase>
  54. <goals><goal>shade</goal></goals>
  55. <configuration>
  56. <transformers>
  57. <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
  58. </transformers>
  59. </configuration>
  60. </execution>
  61. </executions>
  62. </plugin>
  63. --------------------------------------------------
  64. Note that if you have a `main` class you want to automatically call when running `java -jar yourjar.jar`, just add
  65. it to the `transformers`:
  66. [source,xml]
  67. --------------------------------------------------
  68. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  69. <mainClass>org.elasticsearch.demo.Generate</mainClass>
  70. </transformer>
  71. --------------------------------------------------
  72. == Deploying in JBoss EAP6 module
  73. Elasticsearch and Lucene classes need to be in the same JBoss module.
  74. You should define a `module.xml` file like this:
  75. [source,xml]
  76. --------------------------------------------------
  77. <?xml version="1.0" encoding="UTF-8"?>
  78. <module xmlns="urn:jboss:module:1.1" name="org.elasticsearch">
  79. <resources>
  80. <!-- Elasticsearch -->
  81. <resource-root path="elasticsearch-2.0.0.jar"/>
  82. <!-- Lucene -->
  83. <resource-root path="lucene-core-5.1.0.jar"/>
  84. <resource-root path="lucene-analyzers-common-5.1.0.jar"/>
  85. <resource-root path="lucene-queries-5.1.0.jar"/>
  86. <resource-root path="lucene-memory-5.1.0.jar"/>
  87. <resource-root path="lucene-highlighter-5.1.0.jar"/>
  88. <resource-root path="lucene-queryparser-5.1.0.jar"/>
  89. <resource-root path="lucene-sandbox-5.1.0.jar"/>
  90. <resource-root path="lucene-suggest-5.1.0.jar"/>
  91. <resource-root path="lucene-misc-5.1.0.jar"/>
  92. <resource-root path="lucene-join-5.1.0.jar"/>
  93. <resource-root path="lucene-grouping-5.1.0.jar"/>
  94. <resource-root path="lucene-spatial-5.1.0.jar"/>
  95. <resource-root path="lucene-expressions-5.1.0.jar"/>
  96. <!-- Insert other resources here -->
  97. </resources>
  98. <dependencies>
  99. <module name="sun.jdk" export="true" >
  100. <imports>
  101. <include path="sun/misc/Unsafe" />
  102. </imports>
  103. </module>
  104. <module name="org.apache.log4j"/>
  105. <module name="org.apache.commons.logging"/>
  106. <module name="javax.api"/>
  107. </dependencies>
  108. </module>
  109. --------------------------------------------------
  110. include::client.asciidoc[]
  111. include::docs.asciidoc[]
  112. include::search.asciidoc[]
  113. include::aggs.asciidoc[]
  114. include::query-dsl.asciidoc[]
  115. include::indexed-scripts.asciidoc[]
  116. include::admin/index.asciidoc[]