简体   繁体   English

ElasticSearch:设置传输客户端

[英]ElasticSearch : setup transport client

I'm new using ElasticSearch Java API, and i want to create the connection with my instance. 我是使用ElasticSearch Java API的新手,我想与我的实例创建连接。

I followed the instructions here : getting started 我跟着指示操作: 入门

So i get the following code (as simple as on the exemple ! ) : 所以我得到以下代码(就像在示例上一样简单!):

TransportClient mClient = new PreBuiltTransportClient(Settings.EMPTY)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 
                    9300));

But I'm facing an issue about importing classes : TransportClient and Settings, that Eclipse cannot find... 但是我遇到了有关导入类的问题:TransportClient和Settings,Eclipse无法找到...

Here is the maven import : 这是Maven导入:

 <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>5.3.0</version>
</dependency>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.3.0</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.7</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.7</version>
</dependency>

I tried to search bout this issue but didn't find the solution... Eclipse found without any problem the PreBuiltTransportClient. 我试图搜索有关此问题的信息,但没有找到解决方案... Eclipse毫无疑问地找到了PreBuiltTransportClient。

Here is the result of mvn dependency:tee 这是mvn依赖的结果:

[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ poc ---
[INFO] fr.consortnt:poc:war:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- javax:javaee-web-api:jar:6.0:provided
[INFO] +- org.elasticsearch.client:transport:jar:5.3.0:compile
[INFO] |  +- org.elasticsearch:elasticsearch:jar:5.3.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-core:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-analyzers-common:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-backward-codecs:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-grouping:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-highlighter:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-join:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-memory:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-misc:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queries:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queryparser:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-sandbox:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial-extras:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial3d:jar:6.4.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-suggest:jar:6.4.1:compile
[INFO] |  |  +- org.elasticsearch:securesm:jar:1.1:compile
[INFO] |  |  +- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
[INFO] |  |  +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] |  |  +- joda-time:joda-time:jar:2.9.5:compile
[INFO] |  |  +- org.yaml:snakeyaml:jar:1.15:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.8.6:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.6:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.6:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.6:compile
[INFO] |  |  +- com.tdunning:t-digest:jar:3.0:compile
[INFO] |  |  +- org.hdrhistogram:HdrHistogram:jar:2.1.6:compile
[INFO] |  |  \- net.java.dev.jna:jna:jar:4.2.2:compile
[INFO] |  +- org.elasticsearch.plugin:transport-netty3-client:jar:5.3.0:compile
[INFO] |  |  \- io.netty:netty:jar:3.10.6.Final:compile
[INFO] |  +- org.elasticsearch.plugin:transport-netty4-client:jar:5.3.0:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.1.7.Final:compile
[INFO] |  |  +- io.netty:netty-codec:jar:4.1.7.Final:compile
[INFO] |  |  +- io.netty:netty-codec-http:jar:4.1.7.Final:compile
[INFO] |  |  +- io.netty:netty-common:jar:4.1.7.Final:compile
[INFO] |  |  +- io.netty:netty-handler:jar:4.1.7.Final:compile
[INFO] |  |  +- io.netty:netty-resolver:jar:4.1.7.Final:compile
[INFO] |  |  \- io.netty:netty-transport:jar:4.1.7.Final:compile
[INFO] |  +- org.elasticsearch.plugin:reindex-client:jar:5.3.0:compile
[INFO] |  |  \- org.elasticsearch.client:rest:jar:5.3.0:compile
[INFO] |  |     +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  |     +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  |     +- org.apache.httpcomponents:httpasyncclient:jar:4.1.2:compile
[INFO] |  |     +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] |  |     +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |     \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  +- org.elasticsearch.plugin:lang-mustache-client:jar:5.3.0:compile
[INFO] |  |  \- com.github.spullara.mustache.java:compiler:jar:0.9.3:compile
[INFO] |  \- org.elasticsearch.plugin:percolator-client:jar:5.3.0:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.7:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] +- taglibs:standard:jar:1.1.2:compile
[INFO] +- jstl:jstl:jar:1.2:runtime
[INFO] +- org.postgresql:postgresql:jar:9.4.1212:compile
[INFO] \- org.hibernate:hibernate-entitymanager:jar:4.2.15.Final:compile
[INFO]    +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO]    +- dom4j:dom4j:jar:1.6.1:compile
[INFO]    +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO]    +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO]    +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO]    +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO]    \- org.hibernate:hibernate-core:jar:4.2.15.Final:compile
[INFO]       \- antlr:antlr:jar:2.7.7:compile

Any idea about what happens ? 有什么想法吗? I'm pretty sure that it's not a problem from maven configuration because I can import from elasticsearch some of classes needed... 我很确定这不是来自Maven配置的问题,因为我可以从elasticsearch导入一些所需的类...

Thanks in advance ! 提前致谢 !

I am not an eclipse user for a few years now but this looks like an eclipse / maven configuration issue so I recommend you to review your eclipse configuration with maven . 我几年来都不是Eclipse用户,但这看起来像是eclipse / maven配置问题,因此我建议您使用maven查看您的Eclipse配置

I say this is a configuration issue because I have an application working with the following maven dependency configuration: 我说这是一个配置问题,因为我有一个使用以下maven依赖项配置的应用程序:

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <!-- Log Dependencies required by elasticsearch 5 -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j.version}</version>
    </dependency>

Notice that you don't need to add the org.elasticsearch (first one in your list) dependency as this was used when running elasticsearch embedded which is not supported anymore , but it's possible, if this is your case then leave it there, if you're just building a client you don't need that first dependency. 请注意,您不需要添加org.elasticsearch (列表中的第一个)依赖项,因为在运行不再支持Elasticsearch Embedded时使用了此依赖项,但是有可能,如果您的情况如此,请保留它,如果您只是在建立一个客户端,不需要第一个依赖项。

PS - If your eclipse/maven configuration is correct then just maybe you forgot to mvn clean install before running your app? PS-如果您的Eclipse / Maven配置正确,那么也许只是忘记了在运行应用程序之前进行mvn全新安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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