我目前在Spring Boot应用程序中使用以下Elastic客户端库:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.5.3</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.3</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>5.5.3</version>
</dependency>
并在配置类中的以下代码:
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.x.y.repository",queryLookupStrategy= Key.CREATE_IF_NOT_FOUND)
...
public class AppConfiguration extends AbstractAnnotationConfigDispatcherServletInitializer {
...
@Bean
public Client client() {
...
final Settings elasticsearchSettings = Settings.builder().put("http.enabled", "false")/*.put("index.mapping.single_type","false")*/
.put("cluster.name", elasticSearchCluster).build();
logr.debug("elasticSearchCluster--> %d", elasticSearchCluster);
logr.debug("elasticSearchHost --> %d", elasticSearchHost);
try {
TransportClient client1 = new PreBuiltTransportClient(elasticsearchSettings);
client1.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
// return client;
setClient(client1);
} catch (UnknownHostException e) {
logr.error("Not able to connect to Elastic Search: ", e);
}
}
return client;
}
...
上面的应用程序可以连接到ES 5.5.3服务器。我现在想使用客户端依赖项和其余客户端的最新7.6.0版本。
问题:
最佳答案
不,这行不通。这不是特定于Spring Data Elasticsearch的问题,而是源于Elasticsearch库本身的发展。
在Elasticsearch 5和7之间,查询的格式和返回的数据的格式已更改,因此7.6.1客户端无法理解来自5.5.3服务器的响应,而对于其他方向的查询也是如此。
因此,在适应实际的Spring Data Elasticsearch之前,您需要将ES集群从5.5.3迁移到当前版本。
关于elasticsearch - 升级弹性客户端和依赖项以连接到较旧的弹性服务器实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60866220/