在AEM中使用Elasticsearch Rest High Client问题

问题描述 投票:3回答:1

我正在尝试使用Adobe Experience Manager中的Java High Level Rest Client完成Lucene,Solr和Elasticsearch搜索引擎之间的比较的项目。] >>

我在elasticsearh实现]中遇到一些问题。这是代码:

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

    <!-- Elasticseach dependencies -->
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>7.4.0</version>
    </dependency>
    
  • 我正在使用的唯一代码行来自上面的依赖项

    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”,服务器=“本地主机”,端口= 9200,secondPort =9201

  • 错误

    enter image description here

    • IntelliJ的依赖项

    enter image description here

    我知道依赖项版本通常存在问题,但是在这种情况下,所有版本都为[[7.4.0

。此外,elasticsearch 7.4.0v在3个节点上本地运行。此项目在

We.Retail

项目上完成,因此很容易复制。同样,所有具有此错误的代码也可以在这里找到:https://github.com/tadijam64/search-engines-comparison-on-we-retail/tree/elasticsearch-integrationAEM 6.4v。任何信息或想法都值得赞赏。

UPDATE

我尝试添加以下内容以将这些依赖项从外部嵌入,因为它们不是OSGi依赖项:<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>
错误仍然存​​在。我也尝试将其添加到“ export-package”中,但没有帮助。

[通过Elasticsearch documentation,我只需要使用Elasticsearch是

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

但随后

NoClassDefFoundErrors

发生。传递依赖似乎是一个问题。不确定,但是任何想法都值得赞赏。
一些其他建议可以在这里找到:https://forums.adobe.com/thread/2653586

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

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

我正在尝试使用Adobe Experience Manager中的Java High Level Rest Client来完成Lucene,Solr和Elasticsearch搜索引擎之间的比较项目。我在...

maven elasticsearch osgi aem elasticsearch-api
1个回答
2
投票
所以我的猜测是对的,在存在Transitive> true Embed-Transitive>的情况下,不包括传递依存关系。

在问题[上作为搜索引擎运行

elasticsearch

时,以下是必要的:
    我已经在pom.xml中添加了所有
  • transitive依赖项
(版本在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内将所有

第三方依赖项添加为<< [嵌入依赖项] >>,如下所示:

<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> 重要提示:
所有第三方依赖性(OSGi以外的依赖性)必须包含在“嵌入依赖性”中

“ Embed-Transitive”必须设置为true才能包含可传递依赖项

    “ Import-Package”必须包含“ *; resolution:= optional”以排除所有无法解析的依赖项,以便程序可以运行通常
  • 由于某些原因,添加“ elasticsearch”依赖项时在编译时出现错误,对此不重要任务,所以我决定以这种方式忽略它:
  • <_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
  • 尽管是挑战,但我终于解决了。 Google上存在许多相似或相同的问题,因此希望对您有所帮助。感谢所有尝试提供帮助的人。
© www.soinside.com 2019 - 2024. All rights reserved.