java.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. ==== Changes to Query Builders
  67. ===== BoostingQueryBuilder
  68. Removed setters for mandatory positive/negative query. Both arguments now have
  69. to be supplied at construction time already and have to be non-null.
  70. ===== SpanContainingQueryBuilder
  71. Removed setters for mandatory big/little inner span queries. Both arguments now have
  72. to be supplied at construction time already and have to be non-null. Updated
  73. static factory methods in QueryBuilders accordingly.
  74. ===== SpanOrQueryBuilder
  75. Making sure that query contains at least one clause by making initial clause mandatory
  76. in constructor.
  77. Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.
  78. ===== SpanNearQueryBuilder
  79. Removed setter for mandatory slop parameter, needs to be set in constructor now. Also
  80. making sure that query contains at least one clause by making initial clause mandatory
  81. in constructor. Updated the static factory methods in QueryBuilders accordingly.
  82. Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.
  83. ===== SpanNotQueryBuilder
  84. Removed setter for mandatory include/exclude span query clause, needs to be set in constructor now.
  85. Updated the static factory methods in QueryBuilders and tests accordingly.
  86. ===== SpanWithinQueryBuilder
  87. Removed setters for mandatory big/little inner span queries. Both arguments now have
  88. to be supplied at construction time already and have to be non-null. Updated
  89. static factory methods in QueryBuilders accordingly.
  90. ===== WrapperQueryBuilder
  91. Removed `wrapperQueryBuilder(byte[] source, int offset, int length)`. Instead simply
  92. use `wrapperQueryBuilder(byte[] source)`. Updated the static factory methods in
  93. QueryBuilders accordingly.
  94. ===== QueryStringQueryBuilder
  95. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  96. Use the `field(String, float)` method instead.
  97. ===== Operator
  98. Removed the enums called `Operator` from `MatchQueryBuilder`, `QueryStringQueryBuilder`,
  99. `SimpleQueryStringBuilder`, and `CommonTermsQueryBuilder` in favour of using the enum
  100. defined in `org.elasticsearch.index.query.Operator` in an effort to consolidate the
  101. codebase and avoid duplication.
  102. ===== queryName and boost support
  103. Support for `queryName` and `boost` has been streamlined to all of the queries. That is
  104. a breaking change till queries get sent over the network as serialized json rather
  105. than in `Streamable` format. In fact whenever additional fields are added to the json
  106. representation of the query, older nodes might throw error when they find unknown fields.
  107. ===== InnerHitsBuilder
  108. InnerHitsBuilder now has a dedicated addParentChildInnerHits and addNestedInnerHits methods
  109. to differentiate between inner hits for nested vs. parent / child documents. This change
  110. makes the type / path parameter mandatory.
  111. ===== MatchQueryBuilder
  112. Moving MatchQueryBuilder.Type and MatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.Type.
  113. Also reusing new Operator enum.
  114. ===== MoreLikeThisQueryBuilder
  115. Removed `MoreLikeThisQueryBuilder.Item#id(String id)`, `Item#doc(BytesReference doc)`,
  116. `Item#doc(XContentBuilder doc)`. Use provided constructors instead.
  117. Removed `MoreLikeThisQueryBuilder#addLike` in favor of texts and/or items being provided
  118. at construction time. Using arrays there instead of lists now.
  119. Removed `MoreLikeThisQueryBuilder#addUnlike` in favor to using the `unlike` methods
  120. which take arrays as arguments now rather than the lists used before.
  121. The deprecated `docs(Item... docs)`, `ignoreLike(Item... docs)`,
  122. `ignoreLike(String... likeText)`, `addItem(Item... likeItems)` have been removed.
  123. ===== GeoDistanceQueryBuilder
  124. Removing individual setters for lon() and lat() values, both values should be set together
  125. using point(lon, lat).
  126. ===== GeoDistanceRangeQueryBuilder
  127. Removing setters for to(Object ...) and from(Object ...) in favour of the only two allowed input
  128. arguments (String, Number). Removing setter for center point (point(), geohash()) because parameter
  129. is mandatory and should already be set in constructor.
  130. Also removing setters for lt(), lte(), gt(), gte() since they can all be replaced by equivalent
  131. calls to to/from() and inludeLower()/includeUpper().
  132. ===== GeoPolygonQueryBuilder
  133. Require shell of polygon already to be specified in constructor instead of adding it pointwise.
  134. This enables validation, but makes it necessary to remove the addPoint() methods.
  135. ===== MultiMatchQueryBuilder
  136. Moving MultiMatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.ZeroTermsQuery.
  137. Also reusing new Operator enum.
  138. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  139. Use the `field(String, float)` method instead.
  140. ===== MissingQueryBuilder
  141. The MissingQueryBuilder which was deprecated in 2.2.0 is removed. As a replacement use ExistsQueryBuilder
  142. inside a mustNot() clause. So instead of using `new ExistsQueryBuilder(name)` now use
  143. `new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(name))`.
  144. ===== NotQueryBuilder
  145. The NotQueryBuilder which was deprecated in 2.1.0 is removed. As a replacement use BoolQueryBuilder
  146. with added mustNot() clause. So instead of using `new NotQueryBuilder(filter)` now use
  147. `new BoolQueryBuilder().mustNot(filter)`.
  148. ===== TermsQueryBuilder
  149. Remove the setter for `termsLookup()`, making it only possible to either use a TermsLookup object or
  150. individual values at construction time. Also moving individual settings for the TermsLookup (lookupIndex,
  151. lookupType, lookupId, lookupPath) to the separate TermsLookup class, using constructor only and moving
  152. checks for validation there. Removed `TermsLookupQueryBuilder` in favour of `TermsQueryBuilder`.
  153. ===== FunctionScoreQueryBuilder
  154. `add` methods have been removed, all filters and functions must be provided as constructor arguments by
  155. creating an array of `FunctionScoreQueryBuilder.FilterFunctionBuilder` objects, containing one element
  156. for each filter/function pair.
  157. `scoreMode` and `boostMode` can only be provided using corresponding enum members instead
  158. of string values: see `FilterFunctionScoreQuery.ScoreMode` and `CombineFunction`.
  159. `CombineFunction.MULT` has been renamed to `MULTIPLY`.
  160. ===== IdsQueryBuilder
  161. For simplicity, only one way of adding the ids to the existing list (empty by default) is left: `addIds(String...)`
  162. ===== ShapeBuilders
  163. `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.
  164. ===== RescoreBuilder
  165. `RecoreBuilder.Rescorer` was merged with `RescoreBuilder`, which now is an abstract superclass. QueryRescoreBuilder currently is its only implementation.
  166. ===== PhraseSuggestionBuilder
  167. The inner DirectCandidateGenerator class has been moved out to its own class called DirectCandidateGeneratorBuilder.
  168. ===== SortBuilders
  169. The `sortMode` setter in `FieldSortBuilder`, `GeoDistanceSortBuilder` and `ScriptSortBuilder` now
  170. accept a `SortMode` enum instead of a String constant. Also the getter returns the same enum type.
  171. ===== SuggestBuilder
  172. The `setText` method has been changed to `setGlobalText` to make the intent more clear, and a `getGlobalText` method has been added.
  173. The `addSuggestion` method now required the user specified suggestion name, previously used in the ctor of each suggestion.
  174. ===== SuggestionBuilder
  175. The `field` setter has been deleted. Instead the field name needs to be specified as constructor argument.
  176. ==== SearchSourceBuilder
  177. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  178. relevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requests
  179. can now be validated at call time which results in much clearer errors.
  180. The `defaultResourceWindowSize(int)` method has been removed. The window size should be set explicitly on all `RescoreBuilder` objects.
  181. ==== SearchRequestBuilder
  182. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  183. relevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requests
  184. can now be validated at call time which results in much clearer errors.
  185. All highlighter methods have been removed in favor of a single `highlighter(HighlightBuilder)` method.
  186. The `setExtraSource(SearchSourceBuilder)` method has been removed.
  187. The `setTemplateSource(String)` and `setTemplateSource(BytesReference)` methods have been removed. Use `setTemplate(Template)` instead.
  188. `setRescorer(Rescorer)` and `setRescorer(Rescorer, int)` have been removed infavor of `setRescorer(RescoreBuilder)` and `setRescorer(RescoreBuilder, int)`
  189. ==== SearchRequest
  190. All `source` methods have been removed in favor of a single `source(SearchSourceBuilder)` method. This means that all search requests can now be validated
  191. at call time which results in much clearer errors.
  192. All `extraSource` methods have been removed.
  193. All `template` methods have been removed in favor of a new Search Template API. A new `SearchTemplateRequest` now accepts a template and
  194. a `SearchRequest` and must be executed using the new `SearchTemplateAction` action.
  195. ==== SearchResponse
  196. Sort values for `string` fields are now return as `java.lang.String` objects rather than `org.elasticsearch.common.text.Text`.
  197. ==== AggregationBuilder
  198. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  199. relevant builder object (i.e. `subAggregation(AggregationBuilder)` or `subAggregation(PipelineAggregationBuilder)`). This means that all
  200. requests can now be validated at call time which results in much clearer errors.
  201. ==== ValidateQueryRequest
  202. `source(QuerySourceBuilder)`, `source(Map)`, `source(XContentBuilder)`, `source(String)`, `source(byte[])`, `source(byte[], int, int)`,
  203. `source(BytesReference)` and `source()` have been removed in favor of using `query(QueryBuilder)` and `query()`
  204. ==== ValidateQueryRequestBuilder
  205. `setSource()` methods have been removed in favor of using `setQuery(QueryBuilder)`
  206. ==== ExplainRequest
  207. `source(QuerySourceBuilder)`, `source(Map)`, `source(BytesReference)` and `source()` have been removed in favor of using
  208. `query(QueryBuilder)` and `query()`
  209. ==== ExplainRequestBuilder
  210. The `setQuery(BytesReference)` method have been removed in favor of using `setQuery(QueryBuilder)`
  211. ==== ClusterStatsResponse
  212. Removed the `getMemoryAvailable` method from `OsStats`, which could be previously accessed calling
  213. `clusterStatsResponse.getNodesStats().getOs().getMemoryAvailable()`.
  214. ==== setRefresh(boolean) has been removed
  215. `setRefresh(boolean)` has been removed in favor of `setRefreshPolicy(RefreshPolicy)` because there
  216. are now three options (NONE, IMMEDIATE, and WAIT_FOR). `setRefresh(IMMEDIATE)` has the same behavior
  217. as `setRefresh(true)` used to have. See `setRefreshPolicy`'s javadoc for more.
  218. ==== Remove properties support
  219. Some Java APIs (e.g., `IndicesAdminClient#setSettings`) would support Java properties syntax
  220. (line-delimited key=value pairs). This support has been removed.
  221. === Render Search Template Java API has been removed
  222. The Render Search Template Java API including `RenderSearchTemplateAction`, `RenderSearchTemplateRequest` and
  223. `RenderSearchTemplateResponse` has been removed in favor of a new `simulate` option in the Search Template Java API.
  224. This Search Template API is now included in the `lang-mustache` module and the `simulate` flag must be set on the
  225. `SearchTemplateRequest` object.
  226. ==== AnalyzeRequest
  227. The `tokenFilters(String...)` and `charFilters(String...)` methods have been removed
  228. in favor of using `addTokenFilter(String)`/`addTokenFilter(Map)` and `addCharFilter(String)`/`addCharFilter(Map)` each filters
  229. ==== AnalyzeRequestBuilder
  230. The `setTokenFilters(String...)` and `setCharFilters(String...)` methods have been removed
  231. in favor of using `addTokenFilter(String)`/`addTokenFilter(Map)` and `addCharFilter(String)`/`addCharFilter(Map)` each filters