| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 | 
[[breaking_50_java_api_changes]]=== Java API changes==== Transport client  has been movedThe Java transport client has been moved to its own module which can be referenced using:[source,xml]-----<dependency>    <groupId>org.elasticsearch.client</groupId>    <artifactId>transport</artifactId>    <version>5.0.0-alpha5</version></dependency>-----The transport client is now created using the following snippet:[source,java]-----TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));-----For more information please see the {javaclient}java-api.html[Java client documentation]==== Count api has been removedThe deprecated count api has been removed from the Java api, use the search api instead and set size to 0.The following call[source,java]-----client.prepareCount(indices).setQuery(query).get();-----can be replaced with[source,java]-----client.prepareSearch(indices).setSource(new SearchSourceBuilder().size(0).query(query)).get();-----==== Suggest api has been removedThe suggest api has been removed from the Java api, use the suggest option in search api, it has been optimizedfor suggest-only request.The following call[source,java]-----client.prepareSuggest(indices).addSuggestion("foo", SuggestBuilders.completionSuggestion("field").text("s")).get();-----can be replaced with[source,java]-----client.prepareSearch(indices).suggest(new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion("field").text("s"))).get();-----==== Elasticsearch will no longer detect logging implementationsElasticsearch now logs using Log4j 2. Previously if Log4j wasn't on theclasspath it made some effort to degrade to SLF4J or Java logging. Now it willfail to work without the Log4j 2 API. The log4j-over-slf4j bridge ought to workwhen using the Java client. The log4j-1.2-api bridge is used for third-partydependencies that still use the Log4j 1 API. The Elasticsearch server now onlysupports Log4j 2 as configured by `log4j2.properties` and will fail if Log4jisn't present.==== Groovy dependenciesIn previous versions of Elasticsearch, the Groovy scripting capabilitiesdepended on the `org.codehaus.groovy:groovy-all` artifact.  In additionto pulling in the Groovy language, this pulls in a very large set offunctionality, none of which is needed for scripting withinElasticsearch. Aside from the inherent difficulties in managing such alarge set of dependencies, this also increases the surface area forsecurity issues. This dependency has been reduced to the core Groovylanguage `org.codehaus.groovy:groovy` artifact.==== DocumentAlreadyExistsException removed`DocumentAlreadyExistsException` is removed and a `VersionConflictException` is thrown instead (with a bettererror description). This will influence code that use the `IndexRequest.opType()` or `IndexRequest.create()`to index a document only if it doesn't already exist.==== writeConsistencyLevel removed on write requestsIn previous versions of Elasticsearch, the various write requests had a`setWriteConsistencyLevel` method to set the shard consistency level forwrite operations. However, the semantics of write consistency were ambiguous as this is just a pre-operation check to ensure the specified number ofshards were available before the operation commenced. The write consistencylevel did not guarantee that the data would be replicated to those numberof copies by the time the operation finished. The `setWriteConsistencyLevel`method on these write requests has been changed to `setWaitForActiveShards`,which can take a numerical value up to the total number of shard copies or `ActiveShardCount.ALL` for all shard copies. The default is to just waitfor the primary shard to be active before proceeding with the operation. See the section on <<index-wait-for-active-shards,wait for active shards>> for more details.This change affects `IndexRequest`, `IndexRequestBuilder`, `BulkRequest`, `BulkRequestBuilder`, `UpdateRequest`, `UpdateRequestBuilder`, `DeleteRequest`, and `DeleteRequestBuilder`.==== Changes to Query Builders===== BoostingQueryBuilderRemoved setters for mandatory positive/negative query. Both arguments now haveto be supplied at construction time already and have to be non-null.===== SpanContainingQueryBuilderRemoved setters for mandatory big/little inner span queries. Both arguments now haveto be supplied at construction time already and have to be non-null. Updatedstatic factory methods in QueryBuilders accordingly.===== SpanOrQueryBuilderMaking sure that query contains at least one clause by making initial clause mandatoryin constructor.Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.===== SpanNearQueryBuilderRemoved setter for mandatory slop parameter, needs to be set in constructor now. Alsomaking sure that query contains at least one clause by making initial clause mandatoryin constructor. Updated the static factory methods in QueryBuilders accordingly.Renaming method to add clauses from `clause(SpanQueryBuilder)` to `addClause(SpanQueryBuilder)`.===== SpanNotQueryBuilderRemoved setter for mandatory include/exclude span query clause, needs to be set in constructor now.Updated the static factory methods in QueryBuilders and tests accordingly.===== SpanWithinQueryBuilderRemoved setters for mandatory big/little inner span queries. Both arguments now haveto be supplied at construction time already and have to be non-null. Updatedstatic factory methods in QueryBuilders accordingly.===== WrapperQueryBuilderRemoved `wrapperQueryBuilder(byte[] source, int offset, int length)`. Instead simplyuse  `wrapperQueryBuilder(byte[] source)`. Updated the static factory methods inQueryBuilders accordingly.===== QueryStringQueryBuilderRemoved ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.Use the `field(String, float)` method instead.===== OperatorRemoved the enums called `Operator` from `MatchQueryBuilder`, `QueryStringQueryBuilder`,`SimpleQueryStringBuilder`, and `CommonTermsQueryBuilder` in favour of using the enumdefined in `org.elasticsearch.index.query.Operator` in an effort to consolidate thecodebase and avoid duplication.===== queryName and boost supportSupport for `queryName` and `boost` has been streamlined to all of the queries. That isa breaking change till queries get sent over the network as serialized json ratherthan in `Streamable` format. In fact whenever additional fields are added to the jsonrepresentation of the query, older nodes might throw error when they find unknown fields.===== InnerHitsBuilderInnerHitsBuilder now has a dedicated addParentChildInnerHits and addNestedInnerHits methodsto differentiate between inner hits for nested vs. parent / child documents. This changemakes the type / path parameter mandatory.===== MatchQueryBuilderMoving MatchQueryBuilder.Type and MatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.Type.Also reusing new Operator enum.===== MoreLikeThisQueryBuilderRemoved `MoreLikeThisQueryBuilder.Item#id(String id)`, `Item#doc(BytesReference doc)`,`Item#doc(XContentBuilder doc)`. Use provided constructors instead.Removed `MoreLikeThisQueryBuilder#addLike` in favor of texts and/or items being providedat construction time. Using arrays there instead of lists now.Removed `MoreLikeThisQueryBuilder#addUnlike` in favor to using the `unlike` methodswhich take arrays as arguments now rather than the lists used before.The deprecated `docs(Item... docs)`, `ignoreLike(Item... docs)`,`ignoreLike(String... likeText)`, `addItem(Item... likeItems)` have been removed.===== GeoDistanceQueryBuilderRemoving individual setters for lon() and lat() values, both values should be set together using point(lon, lat).===== GeoDistanceRangeQueryBuilderRemoving setters for to(Object ...) and from(Object ...) in favour of the only two allowed inputarguments (String, Number). Removing setter for center point (point(), geohash()) because parameteris mandatory and should already be set in constructor.Also removing setters for lt(), lte(), gt(), gte() since they can all be replaced by equivalentcalls to to/from() and inludeLower()/includeUpper().===== GeoPolygonQueryBuilderRequire shell of polygon already to be specified in constructor instead of adding it pointwise.This enables validation, but makes it necessary to remove the addPoint() methods.===== MultiMatchQueryBuilderMoving MultiMatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.ZeroTermsQuery.Also reusing new Operator enum.Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.Use the `field(String, float)` method instead.===== MissingQueryBuilderThe MissingQueryBuilder which was deprecated in 2.2.0 is removed. As a replacement use ExistsQueryBuilderinside a mustNot() clause. So instead of using `new ExistsQueryBuilder(name)` now use`new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(name))`.===== NotQueryBuilderThe NotQueryBuilder which was deprecated in 2.1.0 is removed. As a replacement use BoolQueryBuilderwith added mustNot() clause. So instead of using `new NotQueryBuilder(filter)` now use`new BoolQueryBuilder().mustNot(filter)`.===== TermsQueryBuilderRemove the setter for `termsLookup()`, making it only possible to either use a TermsLookup object orindividual values at construction time. Also moving individual settings for the TermsLookup (lookupIndex,lookupType, lookupId, lookupPath) to the separate TermsLookup class, using constructor only and movingchecks for validation there. Removed `TermsLookupQueryBuilder` in favour of `TermsQueryBuilder`.===== FunctionScoreQueryBuilder`add` methods have been removed, all filters and functions must be provided as constructor arguments bycreating an array of `FunctionScoreQueryBuilder.FilterFunctionBuilder` objects, containing one elementfor each filter/function pair.`scoreMode` and `boostMode` can only be provided using corresponding enum members insteadof string values: see `FilterFunctionScoreQuery.ScoreMode` and `CombineFunction`.`CombineFunction.MULT` has been renamed to `MULTIPLY`.===== IdsQueryBuilderFor simplicity, only one way of adding the ids to the existing list (empty by default)  is left: `addIds(String...)`===== ShapeBuilders`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.===== RescoreBuilder`RecoreBuilder.Rescorer` was merged with `RescoreBuilder`, which now is an abstract superclass. QueryRescoreBuilder currently is its only implementation.===== PhraseSuggestionBuilderThe inner DirectCandidateGenerator class has been moved out to its own class called DirectCandidateGeneratorBuilder.===== SortBuildersThe `sortMode` setter in `FieldSortBuilder`, `GeoDistanceSortBuilder` and `ScriptSortBuilder` nowaccept a `SortMode` enum instead of a String constant. Also the getter returns the same enum type.===== SuggestBuilderThe `setText` method has been changed to `setGlobalText` to make the intent more clear, and a `getGlobalText` method has been added.The `addSuggestion` method now required the user specified suggestion name, previously used in the ctor of each suggestion.===== SuggestionBuilderThe `field` setter has been deleted. Instead the field name needs to be specified as constructor argument.==== SearchSourceBuilderAll methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing therelevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requestscan now be validated at call time which results in much clearer errors.The `defaultResourceWindowSize(int)` method has been removed. The window size should be set explicitly on all `RescoreBuilder` objects.==== SearchRequestBuilderAll methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing therelevant builder object for that feature (e.g. `HighlightBuilder`, `AggregationBuilder`, `SuggestBuilder`) . This means that all search requestscan now be validated at call time which results in much clearer errors.All highlighter methods have been removed in favor of a single `highlighter(HighlightBuilder)` method.The `setExtraSource(SearchSourceBuilder)` method has been removed.The `setTemplateSource(String)` and `setTemplateSource(BytesReference)` methods have been removed. Use `setTemplate(Template)` instead.`setRescorer(Rescorer)` and `setRescorer(Rescorer, int)` have been removed infavor of `setRescorer(RescoreBuilder)` and `setRescorer(RescoreBuilder, int)`==== SearchRequestAll `source` methods have been removed in favor of a single `source(SearchSourceBuilder)` method. This means that all search requests can now be validatedat call time which results in much clearer errors.All `extraSource` methods have been removed.All `template` methods have been removed in favor of a new Search Template API. A new `SearchTemplateRequest` now accepts a template anda `SearchRequest` and must be executed using the new `SearchTemplateAction` action.==== SearchResponseSort values for `string` fields are now return as `java.lang.String` objects rather than `org.elasticsearch.common.text.Text`.==== AggregationBuilderAll methods which take an `XContentBuilder`, `BytesReference` `Map<String, Object>` or `bytes[]` have been removed in favor of providing therelevant builder object (i.e. `subAggregation(AggregationBuilder)` or `subAggregation(PipelineAggregationBuilder)`). This means that allrequests can now be validated at call time which results in much clearer errors.==== ValidateQueryRequest`source(QuerySourceBuilder)`, `source(Map)`, `source(XContentBuilder)`, `source(String)`, `source(byte[])`, `source(byte[], int, int)`,`source(BytesReference)` and `source()` have been removed in favor of using `query(QueryBuilder)` and `query()`==== ValidateQueryRequestBuilder`setSource()` methods have been removed in favor of using `setQuery(QueryBuilder)`==== ExplainRequest`source(QuerySourceBuilder)`, `source(Map)`, `source(BytesReference)` and `source()` have been removed in favor of using`query(QueryBuilder)` and `query()`==== ExplainRequestBuilderThe `setQuery(BytesReference)` method have been removed in favor of using `setQuery(QueryBuilder)`==== ClusterStatsResponseRemoved the `getMemoryAvailable` method from `OsStats`, which could be previously accessed calling`clusterStatsResponse.getNodesStats().getOs().getMemoryAvailable()`.==== setRefresh(boolean) has been removed`setRefresh(boolean)` has been removed in favor of `setRefreshPolicy(RefreshPolicy)` because thereare now three options (NONE, IMMEDIATE, and WAIT_FOR). `setRefresh(IMMEDIATE)` has the same behavioras `setRefresh(true)` used to have. See `setRefreshPolicy`'s javadoc for more.==== Remove properties supportSome Java APIs (e.g., `IndicesAdminClient#setSettings`) would support Java properties syntax(line-delimited key=value pairs). This support has been removed.==== Render Search Template Java API has been removedThe Render Search Template Java API including `RenderSearchTemplateAction`, `RenderSearchTemplateRequest` and`RenderSearchTemplateResponse` has been removed in favor of a new `simulate` option in the Search Template Java API. This Search Template API is now included in the `lang-mustache` module and the `simulate` flag must be set on the `SearchTemplateRequest` object.==== AnalyzeRequestThe `tokenFilters(String...)` and `charFilters(String...)` methods have been removedin favor of using `addTokenFilter(String)`/`addTokenFilter(Map)` and `addCharFilter(String)`/`addCharFilter(Map)` each filters==== AnalyzeRequestBuilderThe `setTokenFilters(String...)` and `setCharFilters(String...)` methods have been removedin favor of using `addTokenFilter(String)`/`addTokenFilter(Map)` and `addCharFilter(String)`/`addCharFilter(Map)` each filters==== ClusterHealthRequestThe `waitForRelocatingShards(int)` method has been removed in favor of `waitForNoRelocatingShards(boolean)`which instead uses a boolean flag to denote whether the cluster health operation should wait for there tobe no relocating shards in the cluster before returning.==== ClusterHealthRequestBuilderThe `setWaitForRelocatingShards(int)` method has been removed in favor of `setWaitForNoRelocatingShards(boolean)`which instead uses a boolean flag to denote whether the cluster health operation should wait for there tobe no relocating shards in the cluster before returning.==== BlobContainer Interface for Snapshot/RestoreSome methods have been removed from the `BlobContainer` interface for Snapshot/Restore repositories.  In particular,the following three methods have been removed: 1. `deleteBlobs(Collection<String>)` (use `deleteBlob(String)` instead) 2. `deleteBlobsByPrefix(String)` (use `deleteBlob(String)` instead) 3. `writeBlob(String, BytesReference)` (use `writeBlob(String, InputStream, long)` instead)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. The extra `writeBlob` method offered no real advantage to the interface and all calls to `writeBlob(blobName, bytesRef)` can be replaced with:[source,java]-----try (InputStream stream = bytesRef.streamInput()) {    blobContainer.writeBlob(blobName, stream, bytesRef.length());}-----For any custom implementation of the `BlobContainer` interface, these three methods must be removed.
 |