java.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. [[breaking_50_java_api_changes]]
  2. === Java API changes
  3. ==== Count api has been removed
  4. The deprecated count api has been removed from the Java api, use the search api instead and set size to 0.
  5. The following call
  6. [source,java]
  7. -----
  8. client.prepareCount(indices).setQuery(query).get();
  9. -----
  10. can be replaced with
  11. [source,java]
  12. -----
  13. client.prepareSearch(indices).setSource(new SearchSourceBuilder().size(0).query(query)).get();
  14. -----
  15. ==== Suggest api has been removed
  16. The suggest api has been removed from the Java api, use the suggest option in search api, it has been optimized
  17. for suggest-only request.
  18. The following call
  19. [source,java]
  20. -----
  21. client.prepareSuggest(indices).addSuggestion("foo", SuggestBuilders.completionSuggestion("field").text("s")).get();
  22. -----
  23. can be replaced with
  24. [source,java]
  25. -----
  26. client.prepareSearch(indices).suggest(new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion("field").text("s"))).get();
  27. -----
  28. ==== Elasticsearch will no longer detect logging implementations
  29. Elasticsearch now logs only to log4j 1.2. Previously if log4j wasn't on the
  30. classpath it made some effort to degrade to slf4j or java.util.logging. Now it
  31. will fail to work without the log4j 1.2 api. The log4j-over-slf4j bridge ought
  32. to work when using the java client, as should log4j 2's log4j-1.2-api. The
  33. Elasticsearch server now only supports log4j as configured by `logging.yml`
  34. and will fail if log4j isn't present.
  35. ==== Groovy dependencies
  36. In previous versions of Elasticsearch, the Groovy scripting capabilities
  37. depended on the `org.codehaus.groovy:groovy-all` artifact. In addition
  38. to pulling in the Groovy language, this pulls in a very large set of
  39. functionality, none of which is needed for scripting within
  40. Elasticsearch. Aside from the inherent difficulties in managing such a
  41. large set of dependencies, this also increases the surface area for
  42. security issues. This dependency has been reduced to the core Groovy
  43. language `org.codehaus.groovy:groovy` artifact.
  44. ==== DocumentAlreadyExistsException removed
  45. `DocumentAlreadyExistsException` is removed and a `VersionConflictException` is thrown instead (with a better
  46. error description). This will influence code that use the `IndexRequest.opType()` or `IndexRequest.create()`
  47. to index a document only if it doesn't already exist.
  48. ==== Changes to Query Builders
  49. ===== BoostingQueryBuilder
  50. Removed setters for mandatory positive/negative query. Both arguments now have
  51. to be supplied at construction time already and have to be non-null.
  52. ===== SpanContainingQueryBuilder
  53. Removed setters for mandatory big/little inner span queries. Both arguments now have
  54. to be supplied at construction time already and have to be non-null. Updated
  55. static factory methods in QueryBuilders accordingly.
  56. ===== SpanOrQueryBuilder
  57. Making sure that query contains at least one clause by making initial clause mandatory
  58. in constructor.
  59. Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.
  60. ===== SpanNearQueryBuilder
  61. Removed setter for mandatory slop parameter, needs to be set in constructor now. Also
  62. making sure that query contains at least one clause by making initial clause mandatory
  63. in constructor. Updated the static factory methods in QueryBuilders accordingly.
  64. Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.
  65. ===== SpanNotQueryBuilder
  66. Removed setter for mandatory include/exclude span query clause, needs to be set in constructor now.
  67. Updated the static factory methods in QueryBuilders and tests accordingly.
  68. ===== SpanWithinQueryBuilder
  69. Removed setters for mandatory big/little inner span queries. Both arguments now have
  70. to be supplied at construction time already and have to be non-null. Updated
  71. static factory methods in QueryBuilders accordingly.
  72. ===== WrapperQueryBuilder
  73. Removed `wrapperQueryBuilder(byte[] source, int offset, int length)`. Instead simply
  74. use `wrapperQueryBuilder(byte[] source)`. Updated the static factory methods in
  75. QueryBuilders accordingly.
  76. ===== QueryStringQueryBuilder
  77. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  78. Use the `field(String, float)` method instead.
  79. ===== Operator
  80. Removed the enums called `Operator` from `MatchQueryBuilder`, `QueryStringQueryBuilder`,
  81. `SimpleQueryStringBuilder`, and `CommonTermsQueryBuilder` in favour of using the enum
  82. defined in `org.elasticsearch.index.query.Operator` in an effort to consolidate the
  83. codebase and avoid duplication.
  84. ===== queryName and boost support
  85. Support for `queryName` and `boost` has been streamlined to all of the queries. That is
  86. a breaking change till queries get sent over the network as serialized json rather
  87. than in `Streamable` format. In fact whenever additional fields are added to the json
  88. representation of the query, older nodes might throw error when they find unknown fields.
  89. ===== InnerHitsBuilder
  90. InnerHitsBuilder now has a dedicated addParentChildInnerHits and addNestedInnerHits methods
  91. to differentiate between inner hits for nested vs. parent / child documents. This change
  92. makes the type / path parameter mandatory.
  93. ===== MatchQueryBuilder
  94. Moving MatchQueryBuilder.Type and MatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.Type.
  95. Also reusing new Operator enum.
  96. ===== MoreLikeThisQueryBuilder
  97. Removed `MoreLikeThisQueryBuilder.Item#id(String id)`, `Item#doc(BytesReference doc)`,
  98. `Item#doc(XContentBuilder doc)`. Use provided constructors instead.
  99. Removed `MoreLikeThisQueryBuilder#addLike` in favor of texts and/or items being provided
  100. at construction time. Using arrays there instead of lists now.
  101. Removed `MoreLikeThisQueryBuilder#addUnlike` in favor to using the `unlike` methods
  102. which take arrays as arguments now rather than the lists used before.
  103. The deprecated `docs(Item... docs)`, `ignoreLike(Item... docs)`,
  104. `ignoreLike(String... likeText)`, `addItem(Item... likeItems)` have been removed.
  105. ===== GeoDistanceQueryBuilder
  106. Removing individual setters for lon() and lat() values, both values should be set together
  107. using point(lon, lat).
  108. ===== GeoDistanceRangeQueryBuilder
  109. Removing setters for to(Object ...) and from(Object ...) in favour of the only two allowed input
  110. arguments (String, Number). Removing setter for center point (point(), geohash()) because parameter
  111. is mandatory and should already be set in constructor.
  112. Also removing setters for lt(), lte(), gt(), gte() since they can all be replaced by equivalent
  113. calls to to/from() and inludeLower()/includeUpper().
  114. ===== GeoPolygonQueryBuilder
  115. Require shell of polygon already to be specified in constructor instead of adding it pointwise.
  116. This enables validation, but makes it necessary to remove the addPoint() methods.
  117. ===== MultiMatchQueryBuilder
  118. Moving MultiMatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.ZeroTermsQuery.
  119. Also reusing new Operator enum.
  120. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  121. Use the `field(String, float)` method instead.
  122. ===== MissingQueryBuilder
  123. The MissingQueryBuilder which was deprecated in 2.2.0 is removed. As a replacement use ExistsQueryBuilder
  124. inside a mustNot() clause. So instead of using `new ExistsQueryBuilder(name)` now use
  125. `new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(name))`.
  126. ===== NotQueryBuilder
  127. The NotQueryBuilder which was deprecated in 2.1.0 is removed. As a replacement use BoolQueryBuilder
  128. with added mustNot() clause. So instead of using `new NotQueryBuilder(filter)` now use
  129. `new BoolQueryBuilder().mustNot(filter)`.
  130. ===== TermsQueryBuilder
  131. Remove the setter for `termsLookup()`, making it only possible to either use a TermsLookup object or
  132. individual values at construction time. Also moving individual settings for the TermsLookup (lookupIndex,
  133. lookupType, lookupId, lookupPath) to the separate TermsLookup class, using constructor only and moving
  134. checks for validation there. Removed `TermsLookupQueryBuilder` in favour of `TermsQueryBuilder`.
  135. ===== FunctionScoreQueryBuilder
  136. `add` methods have been removed, all filters and functions must be provided as constructor arguments by
  137. creating an array of `FunctionScoreQueryBuilder.FilterFunctionBuilder` objects, containing one element
  138. for each filter/function pair.
  139. `scoreMode` and `boostMode` can only be provided using corresponding enum members instead
  140. of string values: see `FilterFunctionScoreQuery.ScoreMode` and `CombineFunction`.
  141. `CombineFunction.MULT` has been renamed to `MULTIPLY`.
  142. ===== IdsQueryBuilder
  143. For simplicity, only one way of adding the ids to the existing list (empty by default) is left: `addIds(String...)`
  144. ===== ShapeBuilders
  145. `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.
  146. ===== RescoreBuilder
  147. `RecoreBuilder.Rescorer` was merged with `RescoreBuilder`, which now is an abstract superclass. QueryRescoreBuilder currently is its only implementation.
  148. ===== PhraseSuggestionBuilder
  149. The inner DirectCandidateGenerator class has been moved out to its own class called DirectCandidateGeneratorBuilder.
  150. ===== SortBuilders
  151. The `sortMode` setter in `FieldSortBuilder`, `GeoDistanceSortBuilder` and `ScriptSortBuilder` now
  152. accept a `SortMode` enum instead of a String constant. Also the getter returns the same enum type.
  153. ===== SuggestBuilder
  154. The `setText` method has been changed to `setGlobalText` to make the intent more clear, and a `getGlobalText` method has been added.
  155. The `addSuggestion` method now required the user specified suggestion name, previously used in the ctor of each suggestion.
  156. ===== SuggestionBuilder
  157. The `field` setter has been deleted. Instead the field name needs to be specified as constructor argument.
  158. ==== SearchSourceBuilder
  159. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  160. relevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requests
  161. can now be validated at call time which results in much clearer errors.
  162. The `defaultResourceWindowSize(int)` method has been removed. The window size should be set explicitly on all `RescoreBuilder` objects.
  163. ==== SearchRequestBuilder
  164. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  165. relevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requests
  166. can now be validated at call time which results in much clearer errors.
  167. All highlighter methods have been removed in favor of a single `highlighter(HighlightBuilder)` method.
  168. The `setExtraSource(SearchSourceBuilder)` method has been removed.
  169. The `setTemplateSource(String)` and `setTemplateSource(BytesReference)` methods have been removed. Use `setTemplate(Template)` instead.
  170. `setRescorer(Rescorer)` and `setRescorer(Rescorer, int)` have been removed infavor of `setRescorer(RescoreBuilder)` and `setRescorer(RescoreBuilder, int)`
  171. ==== SearchRequest
  172. All `source` methods have been removed in favor of a single `source(SearchSourceBuilder)` method. This means that all search requests can now be validated
  173. at call time which results in much clearer errors.
  174. All `extraSource` methods have been removed.
  175. All `template` methods have been removed in favor of a new Search Template API. A new `SearchTemplateRequest` now accepts a template and
  176. a `SearchRequest` and must be executed using the new `SearchTemplateAction` action.
  177. ==== SearchResponse
  178. Sort values for `string` fields are now return as `java.lang.String` objects rather than `org.elasticsearch.common.text.Text`.
  179. ==== AggregationBuilder
  180. All methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing the
  181. relevant builder object (i.e. `subAggregation(AggregationBuilder)` or `subAggregation(PipelineAggregationBuilder)`). This means that all
  182. requests can now be validated at call time which results in much clearer errors.
  183. ==== ValidateQueryRequest
  184. `source(QuerySourceBuilder)`, `source(Map)`, `source(XContentBuilder)`, `source(String)`, `source(byte[])`, `source(byte[], int, int)`,
  185. `source(BytesReference)` and `source()` have been removed in favor of using `query(QueryBuilder)` and `query()`
  186. ==== ValidateQueryRequestBuilder
  187. `setSource()` methods have been removed in favor of using `setQuery(QueryBuilder)`
  188. ==== ExplainRequest
  189. `source(QuerySourceBuilder)`, `source(Map)`, `source(BytesReference)` and `source()` have been removed in favor of using
  190. `query(QueryBuilder)` and `query()`
  191. ==== ExplainRequestBuilder
  192. The `setQuery(BytesReference)` method have been removed in favor of using `setQuery(QueryBuilder)`
  193. ==== ClusterStatsResponse
  194. Removed the `getMemoryAvailable` method from `OsStats`, which could be previously accessed calling
  195. `clusterStatsResponse.getNodesStats().getOs().getMemoryAvailable()`.
  196. ==== setRefresh(boolean) has been removed
  197. `setRefresh(boolean)` has been removed in favor of `setRefreshPolicy(RefreshPolicy)` because there
  198. are now three options (NONE, IMMEDIATE, and WAIT_FOR). `setRefresh(IMMEDIATE)` has the same behavior
  199. as `setRefresh(true)` used to have. See `setRefreshPolicy`'s javadoc for more.
  200. === Render Search Template Java API has been removed
  201. The Render Search Template Java API including `RenderSearchTemplateAction`, `RenderSearchTemplateRequest` and
  202. `RenderSearchTemplateResponse` has been removed in favor of a new `simulate` option in the Search Template Java API.
  203. This Search Template API is now included in the `lang-mustache` module and the `simulate` flag must be set on the
  204. `SearchTemplateRequest` object.