java.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. ==== Automatically thread client listeners
  34. Previously, the user had to set request listener threads to `true` when on the
  35. client side in order not to block IO threads on heavy operations. This proved
  36. to be very trappy for users, and ended up creating problems that are very hard
  37. to debug.
  38. In 2.0, Elasticsearch automatically threads listeners that are used from the
  39. client when the client is a node client or a transport client. Threading can
  40. no longer be manually set.
  41. ==== Query/filter refactoring
  42. `org.elasticsearch.index.queries.FilterBuilders` has been removed as part of the merge of
  43. queries and filters. These filters are now available in `QueryBuilders` with the same name.
  44. All methods that used to accept a `FilterBuilder` now accept a `QueryBuilder` instead.
  45. In addition some query builders have been removed or renamed:
  46. * `commonTerms(...)` renamed with `commonTermsQuery(...)`
  47. * `queryString(...)` renamed with `queryStringQuery(...)`
  48. * `simpleQueryString(...)` renamed with `simpleQueryStringQuery(...)`
  49. * `textPhrase(...)` removed
  50. * `textPhrasePrefix(...)` removed
  51. * `textPhrasePrefixQuery(...)` removed
  52. * `filtered(...)` removed. Use `filteredQuery(...)` instead.
  53. * `inQuery(...)` removed.
  54. ==== GetIndexRequest
  55. `GetIndexRequest.features()` now returns an array of Feature Enums instead of an array of String values.
  56. The following deprecated methods have been removed:
  57. * `GetIndexRequest.addFeatures(String[])` - Use
  58. `GetIndexRequest.addFeatures(Feature[])` instead
  59. * `GetIndexRequest.features(String[])` - Use
  60. `GetIndexRequest.features(Feature[])` instead.
  61. * `GetIndexRequestBuilder.addFeatures(String[])` - Use
  62. `GetIndexRequestBuilder.addFeatures(Feature[])` instead.
  63. * `GetIndexRequestBuilder.setFeatures(String[])` - Use
  64. `GetIndexRequestBuilder.setFeatures(Feature[])` instead.
  65. ==== BytesQueryBuilder removed
  66. The redundant BytesQueryBuilder has been removed in favour of the
  67. WrapperQueryBuilder internally.
  68. ==== TermsQueryBuilder execution removed
  69. The `TermsQueryBuilder#execution` method has been removed as it has no effect, it is ignored by the
  70. corresponding parser.
  71. ==== ImmutableSettings removed
  72. Use `Settings.builder()` instead of `ImmutableSettings.builder()`.
  73. ==== InetSocketTransportAddress removed
  74. Use `InetSocketTransportAddress(InetSocketAddress address)` instead of `InetSocketTransportAddress(String, int)`.
  75. You can create an InetSocketAddress instance with `InetSocketAddress(String, int)`. For example:
  76. [source,java]
  77. -----------------------------
  78. new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 0));
  79. -----------------------------
  80. ==== Shading and package relocation removed
  81. Elasticsearch used to shade its dependencies and to relocate packages. We no longer use shading or relocation.
  82. You might need to change your imports to the original package names:
  83. * `com.google.common` was `org.elasticsearch.common`
  84. * `com.carrotsearch.hppc` was `org.elasticsearch.common.hppc`
  85. * `jsr166e` was `org.elasticsearch.common.util.concurrent.jsr166e`
  86. * `com.fasterxml.jackson` was `org.elasticsearch.common.jackson`
  87. * `org.joda.time` was `org.elasticsearch.common.joda.time`
  88. * `org.joda.convert` was `org.elasticsearch.common.joda.convert`
  89. * `org.jboss.netty` was `org.elasticsearch.common.netty`
  90. * `com.ning.compress` was `org.elasticsearch.common.compress`
  91. * `com.github.mustachejava` was `org.elasticsearch.common.mustache`
  92. * `com.tdunning.math.stats` was `org.elasticsearch.common.stats`
  93. * `org.apache.commons.lang` was `org.elasticsearch.common.lang`
  94. * `org.apache.commons.cli` was `org.elasticsearch.common.cli.commons`