【问题标题】:Issue with upgrading spring data elastic search to 2.2.0将 spring 数据弹性搜索升级到 2.2.0 的问题
【发布时间】:2016-08-12 15:28:33
【问题描述】:

升级到 ES 2.2 的 spring data elastic search 2.2.0 和 spring boot 1.3.3 后,我遇到以下问题

创建文件中定义的名称为“postingController”的 bean 时出错 创建名为“postingElasticSearchRepository”的 bean 时出错: 创建名为“client”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.NoSuchMethodError: org.elasticsearch.client.transport.TransportClient.builder()Lorg/elasticsearch/client/transport/TransportClient$Builder;

使用 Spring boot 1.2.7 和 Spring data ES 2.2.0 我遇到以下问题

由于找不到内部类,无法评估 org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration#elasticsearchTemplate 的条件。

我分析了以下链接,他们说 Spring Data 不支持 ES 2 版本 https://jira.spring.io/browse/DATAES-211

但在他们的 github 文档中,他们说支持弹性搜索 2.0 https://github.com/spring-projects/spring-data-elasticsearch

请告诉我spring data elastic search是否支持ES 2.2.0如果是请帮我解决我的问题我使用了与上面github页面中描述的相同的配置

【问题讨论】:

  • 所有已发布的 Spring Boot 版本仅适用于 ES 1.x。 Spring Boot 1.4 应该适用于 ES 2.x。我现在必须完全放弃 Spring Boot,才能让 Spring Data ES 2.0.1.RELEASE 和 ES 2.2 正常工作。

标签: elasticsearch spring-data-elasticsearch


【解决方案1】:

我正在使用 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());
    }
}

【讨论】:

  • 谢谢。当然,我会尽力让你知道
  • 很高兴知道这是否解决了它,它没有解决我的问题。
猜你喜欢
  • 2019-11-02
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 2018-06-08
  • 1970-01-01
  • 2020-05-17
  • 2023-04-01
  • 1970-01-01
相关资源
最近更新 更多