java.asciidoc 5.7 KB

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