java.asciidoc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. [[breaking_50_java_api_changes]]
  2. === Java API changes
  3. ==== Transport client has been moved
  4. The Java transport client has been moved to its own module which can be referenced using:
  5. [source,xml]
  6. -----
  7. <dependency>
  8. <groupId>org.elasticsearch.client</groupId>
  9. <artifactId>transport</artifactId>
  10. <version>5.0.0-alpha5</version>
  11. </dependency>
  12. -----
  13. The transport client is now created using the following snippet:
  14. [source,java]
  15. -----
  16. TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
  17. .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
  18. .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
  19. -----
  20. For more information please see the {javaclient}java-api.html[Java client documentation]
  21. ==== Count api has been removed
  22. The deprecated count api has been removed from the Java api, use the search api instead and set size to 0.
  23. The following call
  24. [source,java]
  25. -----
  26. client.prepareCount(indices).setQuery(query).get();
  27. -----
  28. can be replaced with
  29. [source,java]
  30. -----
  31. client.prepareSearch(indices).setSource(new SearchSourceBuilder().size(0).query(query)).get();
  32. -----
  33. ==== Suggest api has been removed
  34. The suggest api has been removed from the Java api, use the suggest option in search api, it has been optimized
  35. for suggest-only request.
  36. The following call
  37. [source,java]
  38. -----
  39. client.prepareSuggest(indices).addSuggestion("foo", SuggestBuilders.completionSuggestion("field").text("s")).get();
  40. -----
  41. can be replaced with
  42. [source,java]
  43. -----
  44. client.prepareSearch(indices).suggest(new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion("field").text("s"))).get();
  45. -----
  46. ==== Elasticsearch will no longer detect logging implementations
  47. Elasticsearch now logs using Log4j 2. Previously if Log4j wasn't on the
  48. classpath it made some effort to degrade to SLF4J or Java logging. Now it will
  49. fail to work without the Log4j 2 API. The log4j-over-slf4j bridge ought to work
  50. when using the Java client. The log4j-1.2-api bridge is used for third-party
  51. dependencies that still use the Log4j 1 API. The Elasticsearch server now only
  52. supports Log4j 2 as configured by `log4j2.properties` and will fail if Log4j
  53. isn't present.
  54. ==== Groovy dependencies
  55. In previous versions of Elasticsearch, the Groovy scripting capabilities
  56. depended on the `org.codehaus.groovy:groovy-all` artifact. In addition
  57. to pulling in the Groovy language, this pulls in a very large set of
  58. functionality, none of which is needed for scripting within
  59. Elasticsearch. Aside from the inherent difficulties in managing such a
  60. large set of dependencies, this also increases the surface area for
  61. security issues. This dependency has been reduced to the core Groovy
  62. language `org.codehaus.groovy:groovy` artifact.
  63. ==== DocumentAlreadyExistsException removed
  64. `DocumentAlreadyExistsException` is removed and a `VersionConflictException` is thrown instead (with a better
  65. error description). This will influence code that use the `IndexRequest.opType()` or `IndexRequest.create()`
  66. to index a document only if it doesn't already exist.
  67. ==== writeConsistencyLevel removed on write requests
  68. In previous versions of Elasticsearch, the various write requests had a
  69. `setWriteConsistencyLevel` method to set the shard consistency level for
  70. write operations. However, the semantics of write consistency were ambiguous
  71. as this is just a pre-operation check to ensure the specified number of
  72. shards were available before the operation commenced. The write consistency
  73. level did not guarantee that the data would be replicated to those number
  74. of copies by the time the operation finished. The `setWriteConsistencyLevel`
  75. method on these write requests has been changed to `setWaitForActiveShards`,
  76. which can take a numerical value up to the total number of shard copies or
  77. `ActiveShardCount.ALL` for all shard copies. The default is to just wait
  78. for the primary shard to be active before proceeding with the operation.
  79. See the section on <<index-wait-for-active-shards,wait for active shards>>
  80. for more details.
  81. This change affects `IndexRequest`, `IndexRequestBuilder`, `BulkRequest`,
  82. `BulkRequestBuilder`, `UpdateRequest`, `UpdateRequestBuilder`, `DeleteRequest`,
  83. and `DeleteRequestBuilder`.
  84. ==== Changes to Query Builders
  85. ===== BoostingQueryBuilder
  86. Removed setters for mandatory positive/negative query. Both arguments now have
  87. to be supplied at construction time already and have to be non-null.
  88. ===== SpanContainingQueryBuilder
  89. Removed setters for mandatory big/little inner span queries. Both arguments now have
  90. to be supplied at construction time already and have to be non-null. Updated
  91. static factory methods in QueryBuilders accordingly.
  92. ===== SpanOrQueryBuilder
  93. Making sure that query contains at least one clause by making initial clause mandatory
  94. in constructor.
  95. Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.
  96. ===== SpanNearQueryBuilder
  97. Removed setter for mandatory slop parameter, needs to be set in constructor now. Also
  98. making sure that query contains at least one clause by making initial clause mandatory
  99. in constructor. Updated the static factory methods in QueryBuilders accordingly.
  100. Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.
  101. ===== SpanNotQueryBuilder
  102. Removed setter for mandatory include/exclude span query clause, needs to be set in constructor now.
  103. Updated the static factory methods in QueryBuilders and tests accordingly.
  104. ===== SpanWithinQueryBuilder
  105. Removed setters for mandatory big/little inner span queries. Both arguments now have
  106. to be supplied at construction time already and have to be non-null. Updated
  107. static factory methods in QueryBuilders accordingly.
  108. ===== WrapperQueryBuilder
  109. Removed `wrapperQueryBuilder(byte[] source, int offset, int length)`. Instead simply
  110. use `wrapperQueryBuilder(byte[] source)`. Updated the static factory methods in
  111. QueryBuilders accordingly.
  112. ===== QueryStringQueryBuilder
  113. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  114. Use the `field(String, float)` method instead.
  115. ===== Operator
  116. Removed the enums called `Operator` from `MatchQueryBuilder`, `QueryStringQueryBuilder`,
  117. `SimpleQueryStringBuilder`, and `CommonTermsQueryBuilder` in favour of using the enum
  118. defined in `org.elasticsearch.index.query.Operator` in an effort to consolidate the
  119. codebase and avoid duplication.
  120. ===== queryName and boost support
  121. Support for `queryName` and `boost` has been streamlined to all of the queries. That is
  122. a breaking change till queries get sent over the network as serialized json rather
  123. than in `Streamable` format. In fact whenever additional fields are added to the json
  124. representation of the query, older nodes might throw error when they find unknown fields.
  125. ===== InnerHitsBuilder
  126. InnerHitsBuilder now has a dedicated addParentChildInnerHits and addNestedInnerHits methods
  127. to differentiate between inner hits for nested vs. parent / child documents. This change
  128. makes the type / path parameter mandatory.
  129. ===== MatchQueryBuilder
  130. Moving MatchQueryBuilder.Type and MatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.Type.
  131. Also reusing new Operator enum.
  132. ===== MoreLikeThisQueryBuilder
  133. Removed `MoreLikeThisQueryBuilder.Item#id(String id)`, `Item#doc(BytesReference doc)`,
  134. `Item#doc(XContentBuilder doc)`. Use provided constructors instead.
  135. Removed `MoreLikeThisQueryBuilder#addLike` in favor of texts and/or items being provided
  136. at construction time. Using arrays there instead of lists now.
  137. Removed `MoreLikeThisQueryBuilder#addUnlike` in favor to using the `unlike` methods
  138. which take arrays as arguments now rather than the lists used before.
  139. The deprecated `docs(Item... docs)`, `ignoreLike(Item... docs)`,
  140. `ignoreLike(String... likeText)`, `addItem(Item... likeItems)` have been removed.
  141. ===== GeoDistanceQueryBuilder
  142. Removing individual setters for lon() and lat() values, both values should be set together
  143. using point(lon, lat).
  144. ===== GeoDistanceRangeQueryBuilder
  145. Removing setters for to(Object ...) and from(Object ...) in favour of the only two allowed input
  146. arguments (String, Number). Removing setter for center point (point(), geohash()) because parameter
  147. is mandatory and should already be set in constructor.
  148. Also removing setters for lt(), lte(), gt(), gte() since they can all be replaced by equivalent
  149. calls to to/from() and inludeLower()/includeUpper().
  150. ===== GeoPolygonQueryBuilder
  151. Require shell of polygon already to be specified in constructor instead of adding it pointwise.
  152. This enables validation, but makes it necessary to remove the addPoint() methods.
  153. ===== MultiMatchQueryBuilder
  154. Moving MultiMatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.ZeroTermsQuery.
  155. Also reusing new Operator enum.
  156. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  157. Use the `field(String, float)` method instead.
  158. ===== MissingQueryBuilder
  159. The MissingQueryBuilder which was deprecated in 2.2.0 is removed. As a replacement use ExistsQueryBuilder
  160. inside a mustNot() clause. So instead of using `new ExistsQueryBuilder(name)` now use
  161. `new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(name))`.
  162. ===== NotQueryBuilder
  163. The NotQueryBuilder which was deprecated in 2.1.0 is removed. As a replacement use BoolQueryBuilder
  164. with added mustNot() clause. So instead of using `new NotQueryBuilder(filter)` now use
  165. `new BoolQueryBuilder().mustNot(filter)`.
  166. ===== TermsQueryBuilder
  167. Remove the setter for `termsLookup()`, making it only possible to either use a TermsLookup object or
  168. individual values at construction time. Also moving individual settings for the TermsLookup (lookupIndex,
  169. lookupType, lookupId, lookupPath) to the separate TermsLookup class, using constructor only and moving
  170. checks for validation there. Removed `TermsLookupQueryBuilder` in favour of `TermsQueryBuilder`.
  171. ===== FunctionScoreQueryBuilder
  172. `add` methods have been removed, all filters and functions must be provided as constructor arguments by
  173. creating an array of `FunctionScoreQueryBuilder.FilterFunctionBuilder` objects, containing one element
  174. for each filter/function pair.
  175. `scoreMode` and `boostMode` can only be provided using corresponding enum members instead
  176. of string values: see `FilterFunctionScoreQuery.ScoreMode` and `CombineFunction`.
  177. `CombineFunction.MULT` has been renamed to `MULTIPLY`.
  178. ===== IdsQueryBuilder
  179. For simplicity, only one way of adding the ids to the existing list (empty by default) is left: `addIds(String...)`
  180. ===== ShapeBuilders
  181. `InternalLineStringBuilder` is removed in favour of `LineStringBuilder`, `InternalPolygonBuilder` in favour of PolygonBuilder` and `Ring` has been replaced with `LineStringBuilder`. Also the abstract base classes `BaseLineStringBuilder` and `BasePolygonBuilder` haven been merged with their corresponding implementations.
  182. ===== RescoreBuilder
  183. `RecoreBuilder.Rescorer` was merged with `RescoreBuilder`, which now is an abstract superclass. QueryRescoreBuilder currently is its only implementation.
  184. ===== PhraseSuggestionBuilder
  185. The inner DirectCandidateGenerator class has been moved out to its own class called DirectCandidateGeneratorBuilder.
  186. ===== SortBuilders
  187. The `sortMode` setter in `FieldSortBuilder`, `GeoDistanceSortBuilder` and `ScriptSortBuilder` now
  188. accept a `SortMode` enum instead of a String constant. Also the getter returns the same enum type.
  189. ===== SuggestBuilder
  190. The `setText` method has been changed to `setGlobalText` to make the intent more clear, and a `getGlobalText` method has been added.
  191. The `addSuggestion` method now required the user specified suggestion name, previously used in the ctor of each suggestion.
  192. ===== SuggestionBuilder
  193. The `field` setter has been deleted. Instead the field name needs to be specified as constructor argument.
  194. ==== SearchSourceBuilder
  195. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  196. relevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requests
  197. can now be validated at call time which results in much clearer errors.
  198. The `defaultResourceWindowSize(int)` method has been removed. The window size should be set explicitly on all `RescoreBuilder` objects.
  199. ==== SearchRequestBuilder
  200. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  201. relevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requests
  202. can now be validated at call time which results in much clearer errors.
  203. All highlighter methods have been removed in favor of a single `highlighter(HighlightBuilder)` method.
  204. The `setExtraSource(SearchSourceBuilder)` method has been removed.
  205. The `setTemplateSource(String)` and `setTemplateSource(BytesReference)` methods have been removed. Use `setTemplate(Template)` instead.
  206. `setRescorer(Rescorer)` and `setRescorer(Rescorer, int)` have been removed infavor of `setRescorer(RescoreBuilder)` and `setRescorer(RescoreBuilder, int)`
  207. ==== SearchRequest
  208. All `source` methods have been removed in favor of a single `source(SearchSourceBuilder)` method. This means that all search requests can now be validated
  209. at call time which results in much clearer errors.
  210. All `extraSource` methods have been removed.
  211. All `template` methods have been removed in favor of a new Search Template API. A new `SearchTemplateRequest` now accepts a template and
  212. a `SearchRequest` and must be executed using the new `SearchTemplateAction` action.
  213. ==== SearchResponse
  214. Sort values for `string` fields are now return as `java.lang.String` objects rather than `org.elasticsearch.common.text.Text`.
  215. ==== AggregationBuilder
  216. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  217. relevant builder object (i.e. `subAggregation(AggregationBuilder)` or `subAggregation(PipelineAggregationBuilder)`). This means that all
  218. requests can now be validated at call time which results in much clearer errors.
  219. ==== ValidateQueryRequest
  220. `source(QuerySourceBuilder)`, `source(Map)`, `source(XContentBuilder)`, `source(String)`, `source(byte[])`, `source(byte[], int, int)`,
  221. `source(BytesReference)` and `source()` have been removed in favor of using `query(QueryBuilder)` and `query()`
  222. ==== ValidateQueryRequestBuilder
  223. `setSource()` methods have been removed in favor of using `setQuery(QueryBuilder)`
  224. ==== ExplainRequest
  225. `source(QuerySourceBuilder)`, `source(Map)`, `source(BytesReference)` and `source()` have been removed in favor of using
  226. `query(QueryBuilder)` and `query()`
  227. ==== ExplainRequestBuilder
  228. The `setQuery(BytesReference)` method have been removed in favor of using `setQuery(QueryBuilder)`
  229. ==== ClusterStatsResponse
  230. Removed the `getMemoryAvailable` method from `OsStats`, which could be previously accessed calling
  231. `clusterStatsResponse.getNodesStats().getOs().getMemoryAvailable()`. It is now replaced with
  232. `clusterStatsResponse.getNodesStats().getOs().getMem()` which exposes `getTotal()`, `getFree()`,
  233. `getUsed()`, `getFreePercent()` and `getUsedPercent()`.
  234. ==== setRefresh(boolean) has been removed
  235. `setRefresh(boolean)` has been removed in favor of `setRefreshPolicy(RefreshPolicy)` because there
  236. are now three options (NONE, IMMEDIATE, and WAIT_FOR). `setRefresh(IMMEDIATE)` has the same behavior
  237. as `setRefresh(true)` used to have. See `setRefreshPolicy`'s javadoc for more.
  238. ==== Remove properties support
  239. Some Java APIs (e.g., `IndicesAdminClient#setSettings`) would support Java properties syntax
  240. (line-delimited key=value pairs). This support has been removed.
  241. ==== Render Search Template Java API has been removed
  242. The Render Search Template Java API including `RenderSearchTemplateAction`, `RenderSearchTemplateRequest` and
  243. `RenderSearchTemplateResponse` has been removed in favor of a new `simulate` option in the Search Template Java API.
  244. This Search Template API is now included in the `lang-mustache` module and the `simulate` flag must be set on the
  245. `SearchTemplateRequest` object.
  246. ==== AnalyzeRequest
  247. The `tokenFilters(String...)` and `charFilters(String...)` methods have been removed
  248. in favor of using `addTokenFilter(String)`/`addTokenFilter(Map)` and `addCharFilter(String)`/`addCharFilter(Map)` each filters
  249. ==== AnalyzeRequestBuilder
  250. The `setTokenFilters(String...)` and `setCharFilters(String...)` methods have been removed
  251. in favor of using `addTokenFilter(String)`/`addTokenFilter(Map)` and `addCharFilter(String)`/`addCharFilter(Map)` each filters
  252. ==== ClusterHealthRequest
  253. The `waitForRelocatingShards(int)` method has been removed in favor of `waitForNoRelocatingShards(boolean)`
  254. which instead uses a boolean flag to denote whether the cluster health operation should wait for there to
  255. be no relocating shards in the cluster before returning.
  256. ==== ClusterHealthRequestBuilder
  257. The `setWaitForRelocatingShards(int)` method has been removed in favor of `setWaitForNoRelocatingShards(boolean)`
  258. which instead uses a boolean flag to denote whether the cluster health operation should wait for there to
  259. be no relocating shards in the cluster before returning.
  260. ==== BlobContainer Interface for Snapshot/Restore
  261. Some methods have been removed from the `BlobContainer` interface for Snapshot/Restore repositories. In particular,
  262. the following three methods have been removed:
  263. 1. `deleteBlobs(Collection<String>)` (use `deleteBlob(String)` instead)
  264. 2. `deleteBlobsByPrefix(String)` (use `deleteBlob(String)` instead)
  265. 3. `writeBlob(String, BytesReference)` (use `writeBlob(String, InputStream, long)` instead)
  266. The `deleteBlob` methods that took multiple blobs as arguments were deleted because no atomic guarantees can be made about either deleting all blobs or deleting none of them, and exception handling in such a situation is ambiguous and best left to the caller. Hence, all delete blob calls use the singular `deleteBlob(String)` method.
  267. The extra `writeBlob` method offered no real advantage to the interface and all calls to `writeBlob(blobName, bytesRef)` can be replaced with:
  268. [source,java]
  269. -----
  270. try (InputStream stream = bytesRef.streamInput()) {
  271. blobContainer.writeBlob(blobName, stream, bytesRef.length());
  272. }
  273. -----
  274. For any custom implementation of the `BlobContainer` interface, these three methods must be removed.