index.asciidoc 5.1 KB

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