java.asciidoc 5.0 KB

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