公司使用elasticsearch2.4.6
版本,因此选择spring-data-elasticsearch 2.0.4.RELEASE
(2.0.4.RELEASE对应原生客户端版本号elasticsearch2.4.6
),版本不一致将会导致报NoNodeAvailableException[None of the configured nodes are available
异常,具体信息如下:
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290) at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207) at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55) at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:286) at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:351) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59) at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.doSearch(ElasticsearchTemplate.java:884) at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForPage(ElasticsearchTemplate.java:271) at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForPage(ElasticsearchTemplate.java:266) at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForList(ElasticsearchTemplate.java:293) at com.hyxdl.elasticsearch.service.impl.ElasticsearchServiceImpl.search(ElasticsearchServiceImpl.java:45)
github官网上spring-data-elasticsearch
与elasticsearch
的对应关系表,但是不太完整,但是还是比较有参考价值的,具体表格如下:
spring data elasticsearch | elasticsearch |
---|---|
3.0.0.RC2 | 5.5.0 |
3.0.0.M4 | 5.4.0 |
2.0.4.RELEASE | 2.4.0 |
2.0.0.RELEASE | 2.2.0 |
1.4.0.M1 | 1.7.3 |
1.3.0.RELEASE | 1.5.2 |
1.2.0.RELEASE | 1.4.4 |
1.1.0.RELEASE | 1.3.2 |
1.0.0.RELEASE | 1.1.1 |
注意:elasticsearch的客户端版本必须与服务端版本主版本保持一致。
参考:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html
The client must have the same major version (e.g. 2.x, or 5.x) as the nodes in the cluster. Clients may connect to clusters which have a different minor version (e.g. 2.3.x) but it is possible that new functionality may not be supported. Ideally, the client should have the same version as the cluster.