升级到弹簧数据弹性搜索2.2.0和弹簧启动1.3.3 for ES 2.2后,我遇到以下问题
在文件中定义名称为'postingController'的bean时出错 创建名为'postingElasticSearchRepository'的bean时出错: 创建名为'client'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NoSuchMethodError:org.elasticsearch.client.transport.TransportClient.builder()Lorg / elasticsearch / client / transport / TransportClient $ Builder;
使用Spring启动1.2.7和Spring数据ES 2.2.0 我正在关注问题
由于找不到内部类,无法评估org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration#elasticsearchTemplate上的条件。
我已经分析了以下链接,他们说Spring数据不支持ES 2版本 https://jira.spring.io/browse/DATAES-211
但是在他们的github文档中,他们说支持弹性搜索2.0 https://github.com/spring-projects/spring-data-elasticsearch
请告诉我弹簧数据弹性搜索是否支持ES 2.2.0如果是,请帮助我解决我的问题我使用了与上面github页面中描述的相同的配置
答案 0 :(得分:0)
我正在使用ES 2.3.2和Spring Data 2.0.5,以下配置适用于我。
我知道你使用的是2.2.0,还是试试看:让我知道它是否适合你。
@Configuration
@EnableElasticsearchRepositories(basePackages = "your base reposity package")
public class EsConfiguration
{
private static final Logger m_log = LoggerFactory.getLogger(EsConfiguration.class);
@Autowired
RProperties properties;
@Bean
public Client client()
{
Client client = null;
Settings settings = Settings.settingsBuilder().put("cluster.name", "ranker.es").build();
try
{
String clusterIps = properties.getProperty("es.hosts");
Integer index = 0;
String[] clusterIpList = StringUtils.split(clusterIps, RConstants.COMMA);
InetSocketTransportAddress[] clusters = new InetSocketTransportAddress[clusterIpList.length];
for (String clusterIp : clusterIpList)
{
InetSocketTransportAddress transportAddress = new InetSocketTransportAddress(InetAddress.getByName(clusterIp),
properties.getIntProperty("es.port"));
clusters[index] = transportAddress;
index++;
}
client = TransportClient.builder().settings(settings).build().addTransportAddresses(clusters);
}
catch (UnknownHostException e)
{
m_log.error("Es Connection failed, application wont work as expected, FIX IT!!!!!!" + e);
}
return client;
}
@Bean
public ElasticsearchOperations elasticsearchTemplate()
{
return new ElasticsearchTemplate(client());
}
}