Reputation: 113
I'm trying to work with ElasticSearch with Java
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
public class EST {
public static void main(String[] args){
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("10.154.12.180", 9200));
Map<String, Object> json = new HashMap<String, Object>();
json.put("user","kimchy");
json.put("postDate",new Date());
json.put("message","trying out Elasticsearch");
IndexResponse response = client.prepareIndex("twitter", "tweet")
.setSource(json)
.execute()
.actionGet();
client.close();
}
}
and added elasticssearch, lucene-core, lucene-queryparser, lucene-analyzers-common and lucene-demo libraries and after run I'm getting NoSuchMethodException
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.lucene.util.UnicodeUtil.UTF16toUTF8(Ljava/lang/CharSequence;IILorg/apache/lucene/util/BytesRef;)V
at org.elasticsearch.common.Strings.toUTF8Bytes(Strings.java:1529)
at org.elasticsearch.common.Strings.toUTF8Bytes(Strings.java:1525)
at org.elasticsearch.search.facet.filter.InternalFilterFacet.<clinit>(InternalFilterFacet.java:40)
at org.elasticsearch.search.facet.TransportFacetModule.configure(TransportFacetModule.java:39)
at org.elasticsearch.common.inject.AbstractModule.configure(AbstractModule.java:60)
at org.elasticsearch.common.inject.spi.Elements$RecordingBinder.install(Elements.java:204)
at org.elasticsearch.common.inject.spi.Elements.getElements(Elements.java:85)
at org.elasticsearch.common.inject.InjectorShell$Builder.build(InjectorShell.java:130)
at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:99)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:59)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:188)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:118)
at estest.EST.main(EST.java:17)
Upvotes: 1
Views: 1587
Reputation: 1
To avoid problems with the compatibility between the java client and ES it`s best to just use the jars delivered by the ES *.zip in the bin folder.
Upvotes: 0
Reputation: 2759
Coincidence is that I just encountered this problem right now - while googling it, I found your question - Google is indeed amazingly fast a indexing, just 6 hours .
Here's how to fix it:
import lucene-core-4.9.0.jar (using maven, gradle or dropping it in your classpath)
the version (probably 4.10) you are using has a different method signature. ES however is linked against 4.9.
Upvotes: 6