Search code examples
javaelasticsearchelasticsearch-plugin

Getting exception while querying from elasticsearch 5.1


Previously I was using elasticsearch 2.2 and now I have upgraded to elasticsearch 5.1 and below is the code for getting the transport-client object, but facing an issue.

Settings settings = Settings.builder().put("cluster.name", 
                elasticConfiguration.getProperty("cluster.name", "elasticsearch")).
                put("client.transport.sniff", true).
                build();


        TransportClient client = new PreBuiltTransportClient(settings);
        for(InetSocketTransportAddress address:nodes){
            (client).addTransportAddress(address);
        }



SearchResponse response = null;
        try {
            LOG.debug("search query "+queryBuilder);
            response = client.prepareSearch(CampaignRepository.INDEX_NAME)
                    .setTypes(getTypeName()).setQuery(queryBuilder).execute()
                    .get();
} catch (InterruptedException | ExecutionException e) {
            LOG.error("Error searching result for " + queryBuilder
                    + " Error message " + e.getMessage());
            // e.printStackTrace();
            throw new CampaignSystemException();
        }

But it gives me an error,

java.util.concurrent.ExecutionException: SendRequestTransportException[[dHFgT6l][10.10.2.231:9300][indices:data/read/search]]; nested: IOException[can not write type [class com.seamless.ers.campaignsystem.api.model.campaign.CampaignState]];

where CampaignState is an enum

please help!!


Solution

  • After doing some R&D, found out there was a bug with elasticsearch. In ES 2.2 it use to accept enum and convert it into String but in 5.1 the same is not happening and this might get fixed in upcoming version