Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Elasticsearch third arty dependency in AEM

Avatar

Level 3

I am having some problems using elasticsearch-rest-high-level-client dependency in my project.

According to Elasticsearch documentation only this should be included:

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

However, there were many NoClassDefinitionFound errors, so I embed the package inside maven-bundle-plugin. I realized that no transitive dependencies are included (altho I have   <Embed-Transitive>true</Embed-Transitive>)
so I've added many of them 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-core,

  elasticsearch-rest-client,

  elasticsearch-x-content,

  elasticsearch-core,

  elasticsearch-secure-sm,

  rank-eval-client,

  lang-mustache-client,

  httpasyncclient,

  lucene-core;

   </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>

Now I have problem while indexing content: Method threw 'java.lang.NoClassDefFoundError' exception. Cannot evaluate org.elasticsearch.action.index.IndexRequest.toString()

So some other dependencies are missing or org.elasticsearch is not properly imported.

Is there a better way to do this? I've seen some with creating bundle with third party dependencies (using Eclipse to create plugin as standard OSGi package), but I am not sure how then to include that dependencies in main (core) bundle. Any other recommendation?

Note:

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

This was needed because when I add elasticsearch artifactid in Embed-package I can not run code because of this error:

[ERROR] Bundle com.adobe.cq.sample:we.retail.core:bundle:3.0.0-SNAPSHOT : Classes found in the wrong directory: {META-INF/versions/9/org/elasticsearch/monitor/jvm/JvmPid.class=org.elasticsearch.monitor.jvm.JvmPid}

[ERROR] Bundle com.adobe.cq.sample:we.retail.core:bundle:3.0.0-SNAPSHOT : Classes found in the wrong directory: {META-INF/versions/9/org/elasticsearch/core/internal/io/Streams.class=org.elasticsearch.core.internal.io.Streams}

[ERROR] Bundle com.adobe.cq.sample:we.retail.core:bundle:3.0.0-SNAPSHOT : Classes found in the wrong directory: {META-INF/versions/9/org/apache/lucene/util/LongsRef.class=org.apache.lucene.util.LongsRef, META-INF/versions/9/org/apache/lucene/search/PointRangeQuery$1.class=org.apache.lucene.search.PointRangeQuery$1, META-INF/versions/9/org/apache/lucene/util/StringHelper.class=org.apache.lucene.util.StringHelper, META-INF/versions/9/org/apache/lucene/util/automaton/Automaton$Builder.class=org.apache.lucene.util.automaton.Automaton$Builder, META-INF/versions/9/org/apache/lucene/util/bkd/BKDRadixSelector$1$1.class=org.apache.lucene.util.bkd.BKDRadixSelector$1$1, META-INF/versions/9/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.class=org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl, META-INF/versions/9/org/apache/lucene/util/bkd/BKDRadixSelector$2$1.class=org.apache.lucene.util.bkd.BKDRadixSelector$2$1, META-INF/versions/9/org/apache/lucene/util/BytesRef.class=org.apache.lucene.util.BytesRef, META-INF/versions/9/org/apache/lucene/document/BinaryPoint$2.class=org.apache.lucene.document.BinaryPoint$2, META-INF/versions/9/org/apache/lucene/document/RangeFieldQuery$QueryType$1.class=org.apache.lucene.document.RangeFieldQuery$QueryType$1, META-INF/versions/9/org/apache/lucene/index/CodecReader.class=org.apache.lucene.index.CodecReader, META-INF/versions/9/org/apache/lucene/util/automaton/Automaton.class=org.apache.lucene.util.automaton.Automaton, META-INF/versions/9/org/apache/lucene/util/bkd/BKDRadixSelector.class=org.apache.lucene.util.bkd.BKDRadixSelector, META-INF/versions/9/org/apache/lucene/util/bkd/MutablePointsReaderUtils$2.class=org.apache.lucene.util.bkd.MutablePointsReaderUtils$2, META-INF/versions/9/org/apache/lucene/document/LongRange.class=org.apache.lucene.document.LongRange, META-INF/versions/9/org/apache/lucene/index/MergeReaderWrapper.class=org.apache.lucene.index.MergeReaderWrapper, META-INF/versions/9/org/apache/lucene/util/CharsRef.class=org.apache.lucene.util.CharsRef, META-INF/versions/9/org/apache/lucene/codecs/compressing/LZ4.class=org.apache.lucene.codecs.compressing.LZ4, META-INF/versions/9/org/apache/lucene/document/LatLonPointDistanceQuery$1.class=org.apache.lucene.document.LatLonPointDistanceQuery$1, META-INF/versions/9/org/apache/lucene/document/DoubleRange.class=org.apache.lucene.document.DoubleRange, META-INF/versions/9/org/apache/lucene/document/FloatRange.class=org.apache.lucene.document.FloatRange, META-INF/versions/9/org/apache/lucene/document/RangeFieldQuery$QueryType$2.class=org.apache.lucene.document.RangeFieldQuery$QueryType$2, META-INF/versions/9/org/apache/lucene/util/bkd/BKDReader.class=org.apache.lucene.util.bkd.BKDReader, META-INF/versions/9/org/apache/lucene/util/CharsRef$UTF16SortedAsUTF8Comparator.class=org.apache.lucene.util.CharsRef$UTF16SortedAsUTF8Comparator, META-INF/versions/9/org/apache/lucene/util/bkd/MutablePointsReaderUtils$3$1.class=org.apache.lucene.util.bkd.MutablePointsReaderUtils$3$1, META-INF/versions/9/org/apache/lucene/util/bkd/HeapPointWriter.class=org.apache.lucene.util.bkd.HeapPointWriter, META-INF/versions/9/org/apache/lucene/document/LatLonPointInPolygonQuery$1$1.class=org.apache.lucene.document.LatLonPointInPolygonQuery$1$1, META-INF/versions/9/org/apache/lucene/search/BooleanScorer$TailPriorityQueue.class=org.apache.lucene.search.BooleanScorer$TailPriorityQueue, META-INF/versions/9/org/apache/lucene/util/bkd/MutablePointsReaderUtils$1$1.class=org.apache.lucene.util.bkd.MutablePointsReaderUtils$1$1, META-INF/versions/9/org/apache/lucene/document/IntRange.class=org.apache.lucene.document.IntRange, META-INF/versions/9/org/apache/lucene/document/LongDistanceFeatureQuery$DistanceScorer$2.class=org.apache.lucene.document.LongDistanceFeatureQuery$DistanceScorer$2, META-INF/versions/9/org/apache/lucene/index/CheckIndex$VerifyPointsVisitor.class=org.apache.lucene.index.CheckIndex$VerifyPointsVisitor, META-INF/versions/9/org/apache/lucene/search/PointInSetQuery$SinglePointVisitor.class=org.apache.lucene.search.PointInSetQuery$SinglePointVisitor, META-INF/versions/9/org/apache/lucene/search/TopFieldCollector.class=org.apache.lucene.search.TopFieldCollector, META-INF/versions/9/org/apache/lucene/document/LatLonPointDistanceFeatureQuery$DistanceScorer$2.class=org.apache.lucene.document.LatLonPointDistanceFeatureQuery$DistanceScorer$2, META-INF/versions/9/org/apache/lucene/util/bkd/BKDWriter$BKDMergeQueue.class=org.apache.lucene.util.bkd.BKDWriter$BKDMergeQueue, META-INF/versions/9/org/apache/lucene/util/bkd/BKDWriter.class=org.apache.lucene.util.bkd.BKDWriter, META-INF/versions/9/org/apache/lucene/util/BytesRefArray.class=org.apache.lucene.util.BytesRefArray, META-INF/versions/9/org/apache/lucene/util/IntsRef.class=org.apache.lucene.util.IntsRef, META-INF/versions/9/org/apache/lucene/index/BitsSlice.class=org.apache.lucene.index.BitsSlice, META-INF/versions/9/org/apache/lucene/document/RangeFieldQuery$QueryType$3.class=org.apache.lucene.document.RangeFieldQuery$QueryType$3, META-INF/versions/9/org/apache/lucene/index/PointValues.class=org.apache.lucene.index.PointValues, META-INF/versions/9/org/apache/lucene/util/bkd/BKDWriter$OneDimensionBKDWriter.class=org.apache.lucene.util.bkd.BKDWriter$OneDimensionBKDWriter}

7 Replies

Avatar

Level 3

Tried that, but many things can not get resolved that way in my case.

Avatar

Level 4
Hi @tadijam47062732 were you able to resolve it in the end? I am facing a similar issue while using elasticsearch in AEM. Can you please let me know?

Avatar

Level 3

@cqsapientu69896 you can see it here - I've manually created elasticsearch as separate OSGi bundles in Eclipse and reuse them in my project. You can check everything here: https://github.com/tadijam64/search-engines-comparison

Avatar

Level 4

Hi @tadijam47062732 thanks for replying we ended up using AWS lambda function but your reply might help someone else facing same issue

Avatar

Employee

Can you run a clean of the Maven project? It could be old data from before making the changes have persisted