java.asciidoc 17 KB

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