在AEM中使用Elasticsearch Rest High Client问题 [英] Using Elasticsearch Rest High Client problem in AEM

查看:118
本文介绍了在AEM中使用Elasticsearch Rest High Client问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

I am trying to use Java High Level Rest Client in Adobe Experience Manager to finish project of comparison between Lucene, Solr and Elasticsearch search engines.

我在 elasticsearh实施时遇到一些问题. 这是代码:

I am having some problems with elasticsearh implementation. Here is the code:

  • 父pom.xml中的依赖性(在核心pom.xml中定义了相同性)

  • Dependency in the parent pom.xml (the same is defined in core pom.xml)

<!-- Elasticseach dependencies -->
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>7.4.0</version>
</dependency>

  • 我正在使用的唯一代码行来自上面的依赖项

  • The only line of code that I am using that is from dependencies above

    try (RestHighLevelClient client = new 
    RestHighLevelClient(RestClient.builder(new HttpHost(server, port, 
    protocol),
      new HttpHost(server, secondPort, protocol)));)
    {
    
    }
    catch (ElasticsearchException e)
    {
        LOG.error("Exception: " + e);
    }
    

  • 协议="http",服务器="localhost",端口= 9200,secondPort = 9201

    protocol = "http", server = "localhost", port = 9200, secondPort = 9201

    • 错误
      • 来自IntelliJ的依赖项

      我知道依赖项版本通常存在问题,但是在这种情况下,所有版本均为 7.4.0 .此外,elasticsearch 7.4.0v在3个节点上本地运行.

      I know that there is usually problem with dependencies versions, but all are 7.4.0 in this case. Also elasticsearch 7.4.0v is running locally on 3 nodes.

      此项目是在 We.Retail 项目上完成的,因此很容易复制.同样,所有包含此错误的代码也可以在此处找到: https://github.com/tadijam64/搜索引擎比较我们/tree/elasticsearch-integration AEM 6.4v.

      This project is done on We.Retail project so it is easy to replicate. Also all the code with this error is available here: https://github.com/tadijam64/search-engines-comparison-on-we-retail/tree/elasticsearch-integration AEM 6.4v.

      任何信息或想法都会受到赞赏.

      Any info or idea is appreciated.

      更新 我尝试添加以下内容以将这些依赖项从外部嵌入,因为它们不是OSGi依赖项:

      UPDATE I tried with adding the following to embed these dependencies externally since they are not OSGi dependencies:

      <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.felix</groupId>
                      <artifactId>maven-scr-plugin</artifactId>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.felix</groupId>
                      <artifactId>maven-bundle-plugin</artifactId>
                      <extensions>true</extensions>
                      <configuration>
                          <instructions>
                              <Embed-Dependency>org.apache.servicemix.bundles.solr-solrj, log4j, noggit, zookeeper,
                                  elasticsearch-rest-high-level-client
                              </Embed-Dependency>
                              <Embed-Transitive>true</Embed-Transitive>
                              <Embed-Directory>OSGI-INF/lib</Embed-Directory>
                              <Export-Package>we.retail.core.model*</Export-Package>
                              <Import-Package>
                                  *;resolution:=optional
                              </Import-Package>
                              <Private-Package>we.retail.core*</Private-Package>
                              <Sling-Model-Packages>
                                  we.retail.core.model
                              </Sling-Model-Packages>
                          </instructions>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      

      错误仍然存​​在.我还尝试将其添加到导出包"中,但没有任何帮助.

      The error remains. I also tried adding it to the "export-package", but nothing helps.

      并通过 Elasticsearch文档,我只需要使用

      <dependency>
          <groupId>org.elasticsearch.client</groupId>
          <artifactId>elasticsearch-rest-high-level-client</artifactId>
          <version>7.4.0</version>
      </dependency>
      

      ,但随后发生 NoClassDefFoundErrors .传递依赖似乎是一个问题.不确定,但是任何想法都会受到赞赏.

      but then NoClassDefFoundErrors occurs. It seems like a problem with transitive dependencies maybe. Not sure, but any idea is appreciated.

      可以在此处找到其他一些建议: https://forums.adobe.com/thread/2653586

      Some other suggestions can be found here: https://forums.adobe.com/thread/2653586

      我也尝试添加它的传递依赖项,例如org.elasticsearch和org.elasticsearch.client,但是它不起作用.同样的错误,只是其他类.

      AEM版本6.4,Java版本:jdk1.8.0_191.jdk

      AEM version 6.4, Java version: jdk1.8.0_191.jdk

      推荐答案

      所以我的猜测是正确的,传递依存关系不包括在Transitive> true</Embed-Transitive>中.存在.

      So my guess was right, transitive dependencies were not included altho Transitive>true</Embed-Transitive> exists.

      在问题 AEM 上运行 elasticsearch 作为搜索引擎时,需要执行以下操作:

      The following is necessary when running elasticsearch as search engine on AEM the problem:

      • 我在pom.xml中添加了所有传递依赖项(版本在parent/pom.xml中定义):

      • I have added all transitive dependencies in pom.xml (versions are defined in parent/pom.xml):

      <!-- Elasticsearch -->
          <dependency>
              <groupId>org.elasticsearch.client</groupId>
              <artifactId>elasticsearch-rest-high-level-client</artifactId>
          </dependency>
          <dependency>
              <groupId>org.elasticsearch.client</groupId>
              <artifactId>elasticsearch-rest-client</artifactId>
          </dependency>
          <dependency>
              <groupId>org.elasticsearch</groupId>
              <artifactId>elasticsearch</artifactId>
          </dependency>
          <dependency>
              <groupId>org.elasticsearch</groupId>
              <artifactId>elasticsearch-x-content</artifactId>
          </dependency>
          <dependency>
              <groupId>org.elasticsearch.plugin</groupId>
              <artifactId>rank-eval-client</artifactId>
          </dependency>
          <dependency>
              <groupId>org.apache.commons</groupId>
              <artifactId>commons-imaging</artifactId>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>org.elasticsearch.plugin</groupId>
              <artifactId>lang-mustache-client</artifactId>
          </dependency>
          <dependency>
              <groupId>org.apache.httpcomponents</groupId>
              <artifactId>httpasyncclient</artifactId>
          </dependency>
      

      重要的是,在 maven-bundle-plugin 之内,将所有第三方依赖项添加为< Embed-Dependency >.

      It is important to add all third-party dependencies as <Embed-Dependency> inside maven-bundle-plugin like this:

          <plugin>
              <groupId>org.apache.felix</groupId>
              <artifactId>maven-bundle-plugin</artifactId>
              <extensions>true</extensions>
              <configuration>
                  <instructions>
                      <Embed-Dependency>org.apache.servicemix.bundles.solr-solrj, noggit,
                          elasticsearch-rest-high-level-client,
                          elasticsearch,
                          elasticsearch-rest-client,
                          elasticsearch-x-content,
                          elasticsearch-core,
                          rank-eval-client,
                          lang-mustache-client,
                          httpasyncclient;
                      </Embed-Dependency>
                      <Embed-Transitive>true</Embed-Transitive>
                      <Embed-Directory>OSGI-INF/lib</Embed-Directory>
                      <Export-Package>we.retail.core.model*</Export-Package>
                      <Import-Package>
                          *;resolution:=optional
                      </Import-Package>
                      <Private-Package>
                          we.retail.core*
                      </Private-Package>
                      <Sling-Model-Packages>
                          we.retail.core.model
                      </Sling-Model-Packages>
                      <_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
                  </instructions>
              </configuration>
          </plugin>
      

      重要提示:

      Important to notice:

      • 所有第三方依赖性(OSGi之外的依赖性)必须包含在嵌入依赖性"中
      • 嵌入传递"必须设置为true才能包含传递依赖项
      • 导入包"必须包含"*; resolution:= optional"以排除所有无法解析的依赖项,以便程序可以运行 通常
      • 由于某些原因,添加"elasticsearch"依赖项时在编译时出现了错误,对此并不重要 任务,所以我决定以这种方式忽略它:
      • All third-party dependencies (the ones outside of OSGi) must be included in the "Embed-Dependency"
      • "Embed-Transitive" must be set to true to include transitive dependencies
      • "Import-Package" must include "*;resolution:=optional" to exclude all dependencies that could not be resolved so that program can run normally
      • For some reason, there was an error in compile time when "elasticsearch" dependency was added which is not important for this task, so I've decided to ignore it this way:

      <_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
      

      尽管遇到了挑战,但我终于解决了. Google上存在许多相似或相同的问题,因此希望对您有所帮助.感谢所有尝试提供帮助的人.

      Though challenge, but I finally resolved it. There are many similar or the same problems on Google, so I hope this will help someone. Thanks to everyone that tried to help.

      这篇关于在AEM中使用Elasticsearch Rest High Client问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆