Elastic 6.5不支持IndexRequest

时间:2018-11-27 12:06:32

标签: java mysql maven elasticsearch

问题

我在Java中使用RestHighLevelClient来构建Crud。

我无法导入这些软件包

        import org.elasticsearch.action.index.IndexRequest;
        import org.elasticsearch.action.index.IndexResponse;
        import org.elasticsearch.ElasticsearchException;
        import org.elasticsearch.action.delete.DeleteRequest;
        import org.elasticsearch.action.delete.DeleteResponse;
        import org.elasticsearch.action.get.GetRequest;
        import org.elasticsearch.action.get.GetResponse;
        import org.elasticsearch.action.index.IndexRequest;
        import org.elasticsearch.action.index.IndexResponse;
        import org.elasticsearch.action.update.UpdateRequest;
        import org.elasticsearch.action.update.UpdateResponse;

错误

  

导入的org.elasticsearch.action无法解决

Java代码

        private static Person insertPerson(Person person) {
                    person.setPersonId(UUID.randomUUID().toString());
                    Map<String, Object> dataMap = new HashMap<String, Object>();
                    dataMap.put("personId", person.getPersonId());
                    dataMap.put("name", person.getName());
                    IndexRequest indexRequest = new IndexRequest(INDEX, TYPE, person.getPersonId()).source(dataMap);
                   IndexResponse response = restHighLevelClient.index(indexRequest);
                  }

Eclipse在说错误

  

此行有多个标记       -无法解决IndexRequest        到一个类型       -无法解决IndexRequest        键入

Pom.xml

                <?xml version="1.0" encoding="UTF-8"?>
                <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <modelVersion>4.0.0</modelVersion>
                  <groupId>org.elasticsearch</groupId>
                  <artifactId>elasticsearch</artifactId>
                  <version>6.5.1</version>
                  <dependencies>
                   <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>elasticsearch</artifactId>
                      <version>6.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>elasticsearch-core</artifactId>
                      <version>6.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                    <groupId>org.elasticsearch.client</groupId>
                    <artifactId>elasticsearch-rest-high-level-client</artifactId>
                    <version>6.5.1</version>
                    </dependency>
                    <dependency>
                      <groupId>com.fasterxml.jackson.core</groupId>
                      <artifactId>jackson-databind</artifactId>
                      <version>2.8.11.3</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>com.fasterxml.jackson.core</groupId>
                      <artifactId>jackson-core</artifactId>
                      <version>2.8.10</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>elasticsearch-secure-sm</artifactId>
                      <version>6.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                   <dependency>
                        <groupId>org.elasticsearch.client</groupId>
                        <artifactId>elasticsearch-rest-client-sniffer</artifactId>
                        <version>6.5.1</version>
                   </dependency>
                    <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>elasticsearch-secure-sm</artifactId>
                      <version>6.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>elasticsearch-x-content</artifactId>
                      <version>6.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-core</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-analyzers-common</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-backward-codecs</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-grouping</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-queries</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-highlighter</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-analyzers-common</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-join</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-memory</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-queries</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-join</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-memory</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-misc</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-queries</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-queryparser</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-queries</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-sandbox</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-sandbox</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-spatial</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-spatial-extras</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-spatial3d</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>io.sgr</groupId>
                          <artifactId>s2-geometry-library-java</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.locationtech.spatial4j</groupId>
                          <artifactId>spatial4j</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-spatial3d</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.lucene</groupId>
                      <artifactId>lucene-suggest</artifactId>
                      <version>7.5.0</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-analyzers-common</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.lucene</groupId>
                          <artifactId>lucene-core</artifactId>
                        </exclusion>
                      </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>elasticsearch-cli</artifactId>
                      <version>6.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>com.carrotsearch</groupId>
                      <artifactId>hppc</artifactId>
                      <version>0.7.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>joda-time</groupId>
                      <artifactId>joda-time</artifactId>
                      <version>2.10.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>com.tdunning</groupId>
                      <artifactId>t-digest</artifactId>
                      <version>3.2</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.hdrhistogram</groupId>
                      <artifactId>HdrHistogram</artifactId>
                      <version>2.1.9</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.locationtech.spatial4j</groupId>
                      <artifactId>spatial4j</artifactId>
                      <version>0.7</version>
                      <scope>compile</scope>
                      <optional>true</optional>
                    </dependency>
                    <dependency>
                      <groupId>org.locationtech.jts</groupId>
                      <artifactId>jts-core</artifactId>
                      <version>1.15.0</version>
                      <scope>compile</scope>
                      <optional>true</optional>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.logging.log4j</groupId>
                      <artifactId>log4j-api</artifactId>
                      <version>2.11.1</version>
                      <scope>compile</scope>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.logging.log4j</groupId>
                      <artifactId>log4j-core</artifactId>
                      <version>2.11.1</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.logging.log4j</groupId>
                          <artifactId>log4j-api</artifactId>
                        </exclusion>
                      </exclusions>
                      <optional>true</optional>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.logging.log4j</groupId>
                      <artifactId>log4j-1.2-api</artifactId>
                      <version>2.11.1</version>
                      <scope>compile</scope>
                      <exclusions>
                        <exclusion>
                          <groupId>org.apache.logging.log4j</groupId>
                          <artifactId>log4j-core</artifactId>
                        </exclusion>
                        <exclusion>
                          <groupId>org.apache.logging.log4j</groupId>
                          <artifactId>log4j-api</artifactId>
                        </exclusion>
                      </exclusions>
                      <optional>true</optional>
                    </dependency>
                    <dependency>
                      <groupId>org.elasticsearch</groupId>
                      <artifactId>jna</artifactId>
                      <version>4.5.1</version>
                      <scope>compile</scope>
                    </dependency>
                  </dependencies>
                  <inceptionYear>2009</inceptionYear>
                  <licenses>
                    <license>
                      <name>The Apache Software License, Version 2.0</name>
                      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
                      <distribution>repo</distribution>
                    </license>
                  </licenses>
                  <developers>
                    <developer>
                      <name>Elastic</name>
                      <url>http://www.elastic.co</url>
                    </developer>
                  </developers>
                  <name>server</name>
                  <description>Elasticsearch subproject :server</description>
                  <url>https://github.com/elastic/elasticsearch</url>
                  <scm>
                    <url>git@github.com:elastic/elasticsearch.git</url>
                  </scm>
                </project>

Pom.xml的引用

https://search.maven.org/artifact/org.elasticsearch/elasticsearch/6.5.1/jar

但在Elastic documentataion中

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-index.html

我尝试安装其他Pom.xml

https://search.maven.org/remotecontent?filepath=org/elasticsearch/client/elasticsearch-rest-high-level-client/6.5.1/elasticsearch-rest-high-level-client-6.5.1.pom

上面的软件包已解决,但此软件包未包含在Maven目录中。

因此,在安装上述Pom.xml之后,RestHighLevel停止工作。

我已经尝试了一切,但无法解决这些问题。

谢谢。

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题

问题出在pom.xml

工作代码

            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <modelVersion>4.0.0</modelVersion>
              <groupId>org.elasticsearch.client</groupId>
              <artifactId>elasticsearch-rest-high-level-client</artifactId>
              <version>6.5.1</version>
              <dependencies>
                <dependency>
                  <groupId>org.elasticsearch</groupId>
                  <artifactId>elasticsearch</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>org.elasticsearch.client</groupId>
                  <artifactId>elasticsearch-rest-client</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                 <dependency>
                  <groupId>org.elasticsearch.client</groupId>
                  <artifactId>transport</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                    <groupId>org.elasticsearch.client</groupId>
                    <artifactId>elasticsearch-rest-client-sniffer</artifactId>
                    <version>6.5.1</version>
               </dependency>
                <dependency>
                  <groupId>org.elasticsearch.plugin</groupId>
                  <artifactId>parent-join-client</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>org.elasticsearch.plugin</groupId>
                  <artifactId>aggs-matrix-stats-client</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>org.elasticsearch.plugin</groupId>
                  <artifactId>rank-eval-client</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>org.elasticsearch.plugin</groupId>
                  <artifactId>lang-mustache-client</artifactId>
                  <version>6.5.1</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>com.fasterxml.jackson.core</groupId>
                  <artifactId>jackson-databind</artifactId>
                  <version>2.8.11.3</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>com.fasterxml.jackson.core</groupId>
                  <artifactId>jackson-core</artifactId>
                  <version>2.8.10</version>
                  <scope>compile</scope>
                </dependency>
                <dependency>
                  <groupId>org.apache.logging.log4j</groupId>
                  <artifactId>log4j-core</artifactId>
                  <version>2.11.1</version>
                  <scope>compile</scope>
               </dependency>
               <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-jdk14</artifactId>
                <version>1.7.25</version>
             </dependency>
               <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-to-slf4j</artifactId>
                    <version>2.8.2</version>
                </dependency>

              </dependencies>

              <inceptionYear>2009</inceptionYear>
              <licenses>
                <license>
                  <name>The Apache Software License, Version 2.0</name>
                  <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
                  <distribution>repo</distribution>
                </license>
              </licenses>
              <developers>
                <developer>
                  <name>Elastic</name>
                  <url>http://www.elastic.co</url>
                </developer>
              </developers>
              <name>rest-high-level</name>
              <description>Elasticsearch subproject :client:rest-high-level</description>
              <url>https://github.com/elastic/elasticsearch</url>
              <scm>
                <url>git@github.com:elastic/elasticsearch.git</url>
              </scm>
            </project>