0
votes

After upgrading to spring data elastic search 2.2.0 and spring boot 1.3.3 for ES 2.2, I am getting the following issues

Error creating bean with name 'postingController' defined in file Error creating bean with name 'postingElasticSearchRepository': Error creating bean with name 'client': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.elasticsearch.client.transport.TransportClient.builder()Lorg/elasticsearch/client/transport/TransportClient$Builder;

With Spring boot 1.2.7 and Spring data ES 2.2.0 I am getting following issue

Could not evaluate condition on org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration#elasticsearchTemplate due to internal class not found.

I have analyzed the following link where they say spring data has no support for ES 2 versions https://jira.spring.io/browse/DATAES-211

but in their github documentation they are saying support for elastic search 2.0 https://github.com/spring-projects/spring-data-elasticsearch

Please let me know whether spring data elastic search has support for ES 2.2.0 If yes please help me solve my issue I have used the same configuration as described in above github page

1
All released versions of Spring Boot only work with ES 1.x. Spring Boot 1.4 is supposed to work with ES 2.x. I had to abandon Spring Boot entirely right now to get Spring Data ES 2.0.1.RELEASE and ES 2.2 to work properly.wxkevin

1 Answers

0
votes

I am using ES 2.3.2 and Spring Data 2.0.5, Following configuration works for me.

I know you are using 2.2.0, Still give a try: Let me know if its worked for you.

@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());
    }
}