java.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. === Java API changes
  2. ==== Transport API construction
  3. The `TransportClient` construction code has changed, it now uses the builder
  4. pattern. Instead of:
  5. [source,java]
  6. --------------------------------------------------
  7. Settings settings = Settings.settingsBuilder()
  8. .put("cluster.name", "myClusterName").build();
  9. Client client = new TransportClient(settings);
  10. --------------------------------------------------
  11. Use the following:
  12. [source,java]
  13. --------------------------------------------------
  14. Settings settings = Settings.settingsBuilder()
  15. .put("cluster.name", "myClusterName").build();
  16. Client client = TransportClient.builder().settings(settings).build();
  17. --------------------------------------------------
  18. The transport client also no longer supports loading settings from config files.
  19. If you have have a config file, you can load into settings yourself before
  20. consturcting the transport client:
  21. [source,java]
  22. --------------------------------------------------
  23. Settings settings = Settings.settingsBuilder()
  24. .loadFromPath(pathToYourSettingsFile).build();
  25. Client client = TransportClient.builder().settings(settings).build();
  26. --------------------------------------------------
  27. ==== Automatically thread client listeners
  28. Previously, the user had to set request listener threads to `true` when on the
  29. client side in order not to block IO threads on heavy operations. This proved
  30. to be very trappy for users, and ended up creating problems that are very hard
  31. to debug.
  32. In 2.0, Elasticsearch automatically threads listeners that are used from the
  33. client when the client is a node client or a transport client. Threading can
  34. no longer be manually set.
  35. ==== Query/filter refactoring
  36. `org.elasticsearch.index.queries.FilterBuilders` has been removed as part of the merge of
  37. queries and filters. These filters are now available in `QueryBuilders` with the same name.
  38. All methods that used to accept a `FilterBuilder` now accept a `QueryBuilder` instead.
  39. In addition some query builders have been removed or renamed:
  40. * `commonTerms(...)` renamed with `commonTermsQuery(...)`
  41. * `queryString(...)` renamed with `queryStringQuery(...)`
  42. * `simpleQueryString(...)` renamed with `simpleQueryStringQuery(...)`
  43. * `textPhrase(...)` removed
  44. * `textPhrasePrefix(...)` removed
  45. * `textPhrasePrefixQuery(...)` removed
  46. * `filtered(...)` removed. Use `filteredQuery(...)` instead.
  47. * `inQuery(...)` removed.
  48. ==== GetIndexRequest
  49. `GetIndexRequest.features()` now returns an array of Feature Enums instead of an array of String values.
  50. The following deprecated methods have been removed:
  51. * `GetIndexRequest.addFeatures(String[])` - Use
  52. `GetIndexRequest.addFeatures(Feature[])` instead
  53. * `GetIndexRequest.features(String[])` - Use
  54. `GetIndexRequest.features(Feature[])` instead.
  55. * `GetIndexRequestBuilder.addFeatures(String[])` - Use
  56. `GetIndexRequestBuilder.addFeatures(Feature[])` instead.
  57. * `GetIndexRequestBuilder.setFeatures(String[])` - Use
  58. `GetIndexRequestBuilder.setFeatures(Feature[])` instead.
  59. ==== BytesQueryBuilder removed
  60. The redundant BytesQueryBuilder has been removed in favour of the
  61. WrapperQueryBuilder internally.
  62. ==== TermsQueryBuilder execution removed
  63. The `TermsQueryBuilder#execution` method has been removed as it has no effect, it is ignored by the
  64. corresponding parser.
  65. ==== ImmutableSettings removed
  66. Use `Settings.builder()` instead of `ImmutableSettings.builder()`.
  67. ==== InetSocketTransportAddress removed
  68. Use `InetSocketTransportAddress(InetSocketAddress address)` instead of `InetSocketTransportAddress(String, int)`.
  69. You can create an InetSocketAddress instance with `InetSocketAddress(String, int)`. For example:
  70. [source,java]
  71. -----------------------------
  72. new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 0));
  73. -----------------------------
  74. ==== Shading and package relocation removed
  75. Elasticsearch used to shade its dependencies and to relocate packages. We no longer use shading or relocation.
  76. You might need to change your imports to the original package names:
  77. * `com.google.common` was `org.elasticsearch.common`
  78. * `com.carrotsearch.hppc` was `org.elasticsearch.common.hppc`
  79. * `jsr166e` was `org.elasticsearch.common.util.concurrent.jsr166e`
  80. * `com.fasterxml.jackson` was `org.elasticsearch.common.jackson`
  81. * `org.joda.time` was `org.elasticsearch.common.joda.time`
  82. * `org.joda.convert` was `org.elasticsearch.common.joda.convert`
  83. * `org.jboss.netty` was `org.elasticsearch.common.netty`
  84. * `com.ning.compress` was `org.elasticsearch.common.compress`
  85. * `com.github.mustachejava` was `org.elasticsearch.common.mustache`
  86. * `com.tdunning.math.stats` was `org.elasticsearch.common.stats`
  87. * `org.apache.commons.lang` was `org.elasticsearch.common.lang`
  88. * `org.apache.commons.cli` was `org.elasticsearch.common.cli.commons`