简体   繁体   中英

ElasticSearch Lucene UnicodeUtil not found

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)

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.

为了避免Java客户端和ES之间的兼容性问题,最好只使用bin文件夹中ES * .zip提供的jar。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM