|
| 1 | +[[elasticsearch-migration-guide-4.4-5.0]] |
| 2 | += Upgrading from 4.4.x to 5.0.x |
| 3 | + |
| 4 | +This section describes breaking changes from version 4.4.x to 5.0.x and how removed features can be replaced by new |
| 5 | +introduced features. |
| 6 | + |
| 7 | +[[elasticsearch-migration-guide-4.4-4.5.deprecations]] |
| 8 | +== Deprecations |
| 9 | + |
| 10 | +=== `org.springframework.data.elasticsearch.client.erhlc` package |
| 11 | + |
| 12 | +See <<elasticsearch-migration-guide-4.4-5.0.breaking-changes-packages>>, all classes in this package have been |
| 13 | +deprecated, as the default client implementations to use are the ones based on the new Java Client from |
| 14 | +Elasticsearch, se <<elasticsearch-migration-guide-4.4-5.0.new-clients>> |
| 15 | + |
| 16 | +[[elasticsearch-migration-guide-4.4-5.0.breaking-changes]] |
| 17 | +== Breaking Changes |
| 18 | + |
| 19 | +=== Removal of deprecated calls |
| 20 | + |
| 21 | +==== suggest calls in operations interfaces have been removed |
| 22 | + |
| 23 | +Both `SearchOperations` and `ReactiveSearchOperations` had deprecated calls that were using Elasticsearch classes as |
| 24 | +parameters. These now have been removed and so the dependency on Elasticsearch classes in these APIs has been cleaned. |
| 25 | + |
| 26 | +[[elasticsearch-migration-guide-4.4-5.0.breaking-changes-packages]] |
| 27 | +=== Package changes |
| 28 | + |
| 29 | +All the classes that are using or depend on the deprecated Elasticsearch `RestHighLevelClient` have been moved to the |
| 30 | +package `org.springframework.data.elasticsearch.client.erhlc`. By this change we now have a clear separation of code |
| 31 | +using the old deprecated Elasticsearch libraries, code using the new Elasticsearch client and code that is |
| 32 | +independent of the client implementation. Also the reactive implementation that was provided up to now has been moved |
| 33 | +here, as this implementation contains code that was copied and adapted from Elasticsearch libraries. |
| 34 | + |
| 35 | + |
| 36 | +[[elasticsearch-migration-guide-4.4-5.0.new-clients]] |
| 37 | +== New Elasticsearch client |
| 38 | + |
| 39 | +Spring Data Elasticsearch now uses the new `ElasticsearchClient` and has |
| 40 | +deprecated the use of the previous `RestHighLevelClient`. |
| 41 | + |
| 42 | +=== How to use the new client |
| 43 | + |
| 44 | +In order to use the new client the following steps are necessary: |
| 45 | + |
| 46 | +==== Add dependencies |
| 47 | + |
| 48 | +The dependencies for the new Elasticsearch client are still optional in Spring Data Elasticsearch so they need to be added explicitly: |
| 49 | + |
| 50 | +==== |
| 51 | +[source,xml] |
| 52 | +---- |
| 53 | +<dependencies> |
| 54 | + <dependency> |
| 55 | + <groupId>co.elastic.clients</groupId> |
| 56 | + <artifactId>elasticsearch-java</artifactId> |
| 57 | + <version>7.17.3</version> |
| 58 | + <exclusions> |
| 59 | + <exclusion> |
| 60 | + <groupId>commons-logging</groupId> |
| 61 | + <artifactId>commons-logging</artifactId> |
| 62 | + </exclusion> |
| 63 | + </exclusions> |
| 64 | + </dependency> |
| 65 | + <dependency> |
| 66 | + <groupId>org.elasticsearch.client</groupId> |
| 67 | + <artifactId>elasticsearch-rest-client</artifactId> <!-- is Apache 2--> |
| 68 | + <version>7.17.3</version> |
| 69 | + <exclusions> |
| 70 | + <exclusion> |
| 71 | + <groupId>commons-logging</groupId> |
| 72 | + <artifactId>commons-logging</artifactId> |
| 73 | + </exclusion> |
| 74 | + </exclusions> |
| 75 | + </dependency> |
| 76 | +</dependencies> |
| 77 | +---- |
| 78 | +==== |
| 79 | + |
| 80 | +When using Spring Boot, it is necessary to set the following property in the _pom.xml_. |
| 81 | + |
| 82 | +==== |
| 83 | +[source,xml] |
| 84 | +---- |
| 85 | +<properties> |
| 86 | + <jakarta-json.version>2.0.1</jakarta-json.version> |
| 87 | +</properties> |
| 88 | +---- |
| 89 | +==== |
| 90 | + |
| 91 | +==== New configuration classes |
| 92 | + |
| 93 | +===== Imperative style |
| 94 | + |
| 95 | +In order configure Spring Data Elasticsearch to use the new client, it is necessary to create a configuration bean that derives from `org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration`: |
| 96 | + |
| 97 | +==== |
| 98 | +[source,java] |
| 99 | +---- |
| 100 | +@Configuration |
| 101 | +public class NewRestClientConfig extends ElasticsearchConfiguration { |
| 102 | +
|
| 103 | + @Override |
| 104 | + public ClientConfiguration clientConfiguration() { |
| 105 | + return ClientConfiguration.builder() // |
| 106 | + .connectedTo("localhost:9200") // |
| 107 | + .build(); |
| 108 | + } |
| 109 | +} |
| 110 | +---- |
| 111 | +==== |
| 112 | + |
| 113 | +The configuration is done in the same way as with the old client, but it is not necessary anymore to create more than the configuration bean. |
| 114 | +With this configuration, the following beans will be available in the Spring application context: |
| 115 | + |
| 116 | +* a `RestClient` bean, that is the configured low level `RestClient` that is used by the Elasticsearch client |
| 117 | +* an `ElasticsearchClient` bean, this is the new client that uses the `RestClient` |
| 118 | +* an `ElasticsearchOperations` bean, available with the bean names _elasticsearchOperations_ and _elasticsearchTemplate_, this uses the `ElasticsearchClient` |
| 119 | + |
| 120 | +===== Reactive style |
| 121 | + |
| 122 | +To use the new client in a reactive environment the only difference is the class from which to derive the configuration: |
| 123 | + |
| 124 | +==== |
| 125 | +[source,java] |
| 126 | +---- |
| 127 | +@Configuration |
| 128 | +public class NewRestClientConfig extends ReactiveElasticsearchConfiguration { |
| 129 | +
|
| 130 | + @Override |
| 131 | + public ClientConfiguration clientConfiguration() { |
| 132 | + return ClientConfiguration.builder() // |
| 133 | + .connectedTo("localhost:9200") // |
| 134 | + .build(); |
| 135 | + } |
| 136 | +} |
| 137 | +---- |
| 138 | +==== |
| 139 | + |
| 140 | +With this configuration, the following beans will be available in the Spring application context: |
| 141 | + |
| 142 | +* a `RestClient` bean, that is the configured low level `RestClient` that is used by the Elasticsearch client |
| 143 | +* an `ReactiveElasticsearchClient` bean, this is the new reactive client that uses the `RestClient` |
| 144 | +* an `ReactiveElasticsearchOperations` bean, available with the bean names _reactiveElasticsearchOperations_ and _reactiveElasticsearchTemplate_, this uses the `ReactiveElasticsearchClient` |
0 commit comments