英文:
Elasticsearch 7.8 with Magnolia 6.2.x
问题
我想使用最新的 Elasticsearch 版本(7.8.0)与最新的 Mgnl(CE)版本(当前为6.2.2)。在一些旧项目中,它们经常使用 Elasticsearch 版本<3.6,并且对于所有的 API 调用,如搜索/索引查询,它们使用 Elastic 的旧传输客户端。该客户端将在 Elastic 的 v8 中被移除,并将由 Elastic 的 Rest-High-Level-Client API 替代。
为了进行测试,我通过 mvn 构建原型生成方式使用空白的 mgnl 6.2.2,并在 mgnl 中设置了一个简单的模块,其中包含一个虚拟页面和虚拟组件。为了测试结果,我修改了虚拟组件,调用以下代码片段作为组件模型。
我的模型:
package com.test.model;
import javax.jcr.Node;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import info.magnolia.rendering.model.RenderingModel;
import info.magnolia.rendering.model.RenderingModelImpl;
import info.magnolia.rendering.template.TemplateDefinition;
public class TestModel extends RenderingModelImpl<TemplateDefinition> {
public TestModel(Node content, TemplateDefinition definition, RenderingModel<?> parent) {
super(content, definition, parent);
}
public void init( ) {
SearchRequest test = new SearchRequest();
SearchSourceBuilder testSource = new SearchSourceBuilder();
test.source(testSource);
System.out.println("test done");
}
}
以下是我的 pom 文件:
<!-- Test-Module pom.xml -->
<!-- ... -->
<!-- parent-pom pom.xml -->
<!-- ... -->
如果我尝试设置一个类似 TestModel 中所写的使用 SearchRequest 和 SearchSourceBuilder 的简单搜索请求,我会得到以下异常:
Caused by: java.lang.NoSuchFieldError: LATEST
at org.elasticsearch.Version.<clinit>(Version.java:59)
at org.elasticsearch.common.logging.DeprecationLogger.<clinit>(DeprecationLogger.java:143)
at org.elasticsearch.search.builder.SearchSourceBuilder.<clinit>(SearchSourceBuilder.java:83)
at com.test.model.TestModel.init(TestModel.java:20)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45009)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45012)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1505)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:72)
在阅读了一些论坛后,我注意到这是由于不同版本的 lucene-core 导致的问题。您可以通过以下命令查看所包含的 lucene-core 版本:
mvn dependency:tree -Dverbose -Dincludes=org.apache.lucene
通过上述输出,您可以看到依赖 mgnl-core 包含了 jackrabbit-core 2.20.0 中的 lucene-core v3.6。如果您尝试排除 lucene v3.6 并仅包含来自 elasticsearch v7.8 的版本,您将遇到另一个异常。
我希望这些信息对您有所帮助。如果您有进一步的问题或需要更多帮助,请随时提问。
英文:
i want to use the latest elasticsearch version (7.8.0) with the latest Mgnl (CE) version (currently 6.2.2). In some older project they often use elastic with version <3.6 and for all api calls like search / indexing queries they use the old transport client of Elastic. That client will be removed with v8 of elastic and will be replaced by the Rest-High-Level-Client Api of elastic.
For my test i used a blank mgnl 6.2.2 via mvn archetype generation and setup a simple module from mgnl with a dummy page and dummy component. To test the result, i modified that dummy to call the following code snippet as component model.
My model :
package com.test.model;
import javax.jcr.Node;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import info.magnolia.rendering.model.RenderingModel;
import info.magnolia.rendering.model.RenderingModelImpl;
import info.magnolia.rendering.template.TemplateDefinition;
public class TestModel extends RenderingModelImpl<TemplateDefinition>{
public TestModel(Node content, TemplateDefinition definition, RenderingModel<?> parent) {
super(content, definition, parent);
}
public void init( ) {
SearchRequest test = new SearchRequest();
SearchSourceBuilder testSource = new SearchSourceBuilder();
test.source(testSource);
System.out.println("test done");
}
}
here are my pom's :
Test-Module :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test</groupId>
<artifactId>mgnl</artifactId>
<version>1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>mgnl-web</artifactId>
<packaging>jar</packaging>
<name>mgnl-web Magnolia Module</name>
<!-- <description>Please uncomment and fill in ...</description> -->
<properties>
<magnoliaBundleVersion>6.2.2</magnoliaBundleVersion>
<javaVersion>1.8</javaVersion>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>info.magnolia.bundle</groupId>
<artifactId>magnolia-bundle-parent</artifactId>
<version>${magnoliaBundleVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-rendering</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.8.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.8.0</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-core</artifactId>
</dependency>
<!-- TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
</configuration>
</plugin>
</plugins>
<!-- default resources configuration which will filter the module descriptor -->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>META-INF/magnolia/*</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>magnolia.public</id>
<url>https://nexus.magnolia-cms.com/content/groups/public</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- IF YOU NEED MODULES FROM THE ENTERPRISE VERSION, UNCOMMENT THE FOLLOWING
REPOSITORY -->
<!-- <repository> <id>magnolia.enterprise.releases</id> <url>https://nexus.magnolia-cms.com/content/repositories/magnolia.enterprise.releases</url>
<snapshots> <enabled>false</enabled> </snapshots> </repository> -->
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
</project>
parent-pom (Untouched generation via mgnl mvn archetype) :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>mgnl</artifactId>
<name>mgnl (parent pom)</name>
<version>1</version>
<packaging>pom</packaging>
<properties>
<magnoliaBundleVersion>6.2.2</magnoliaBundleVersion>
<javaVersion>1.8</javaVersion>
</properties>
<!-- Fill the following in, so you can use the release plugin -->
<scm>
<connection />
<developerConnection />
<url />
</scm>
<dependencyManagement>
<dependencies>
<!-- Option A -->
<!-- Importing dependencyManagement of CE bundle. -->
<dependency>
<groupId>info.magnolia.bundle</groupId>
<artifactId>magnolia-bundle-parent</artifactId>
<version>${magnoliaBundleVersion}</version>
<type>pom</type>
<scope>import</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Option B -->
<!-- If you want to use the DX CORE. -->
<!-- <dependency> <groupId>info.magnolia.dx</groupId> <artifactId>magnolia-dx-core-parent</artifactId>
<version>${magnoliaBundleVersion}</version> <type>pom</type> <scope>import</scope>
</dependency> -->
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
</configuration>
</plugin>
</plugins>
<!-- default resources configuration which will filter your module descriptors -->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>META-INF/magnolia/*</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>magnolia.public</id>
<url>https://nexus.magnolia-cms.com/content/groups/public</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- IF YOU NEED MODULES FROM THE ENTERPRISE VERSION, UNCOMMENT THE FOLLOWING
REPOSITORY -->
<!-- <repository> <id>magnolia.enterprise.releases</id> <url>https://nexus.magnolia-cms.com/content/repositories/magnolia.enterprise.releases</url>
<snapshots> <enabled>false</enabled> </snapshots> </repository> -->
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<modules>
<module>mgnl-webapp</module>
<module>mgnl-web</module>
</modules>
</project>
If i try to setup a simple SearchRequest with SearchSourceBuilder like that one written in the TestModel i got the following exception :
Caused by: java.lang.NoSuchFieldError: LATEST
at org.elasticsearch.Version.<clinit>(Version.java:59)
at org.elasticsearch.common.logging.DeprecationLogger.<clinit>(DeprecationLogger.java:143)
at org.elasticsearch.search.builder.SearchSourceBuilder.<clinit>(SearchSourceBuilder.java:83)
at com.test.model.TestModel.init(TestModel.java:20)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45009)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45012)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1505)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:72)
after reading some forums i noticed that it happens if there are different versions of lucene-core so i figured out which versions are presented with :
mvn dependency:tree -Dverbose -Dincludes=org.apache.lucene
and got the following result :
[INFO] -------------------------< com.test:mgnl-web >--------------------------
[INFO] Building mgnl-web Magnolia Module 1 [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ mgnl-web ---
[INFO] com.test:mgnl-web:jar:1
[INFO] +- org.elasticsearch:elasticsearch:jar:7.8.0:compile
[INFO] | +- org.apache.lucene:lucene-core:jar:3.6.0:compile
[INFO] | +- org.apache.lucene:lucene-analyzers-common:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-backward-codecs:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-grouping:jar:8.5.1:compile
[INFO] | | +- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | | \- (org.apache.lucene:lucene-queries:jar:8.5.1:compile - omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-highlighter:jar:8.5.1:compile
[INFO] | | +- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | | +- (org.apache.lucene:lucene-memory:jar:8.5.1:compile - omitted for duplicate)
[INFO] | | \- (org.apache.lucene:lucene-queries:jar:8.5.1:compile - omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-join:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-memory:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-misc:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-queries:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-queryparser:jar:8.5.1:compile
[INFO] | | +- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | | +- (org.apache.lucene:lucene-queries:jar:8.5.1:compile - omitted for duplicate)
[INFO] | | \- (org.apache.lucene:lucene-sandbox:jar:8.5.1:compile - omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-sandbox:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-spatial-extras:jar:8.5.1:compile
[INFO] | | +- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | | \- (org.apache.lucene:lucene-spatial3d:jar:8.5.1:compile - omitted for duplicate)
[INFO] | +- org.apache.lucene:lucene-spatial3d:jar:8.5.1:compile
[INFO] | | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] | \- org.apache.lucene:lucene-suggest:jar:8.5.1:compile
[INFO] | +- (org.apache.lucene:lucene-analyzers-common:jar:8.5.1:compile - omitted for duplicate)
[INFO] | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] \- info.magnolia:magnolia-core:jar:6.2.2:compile
[INFO] +- org.apache.jackrabbit:jackrabbit-core:jar:2.20.0:compile
[INFO] | \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
[INFO] \- (org.apache.lucene:lucene-core:jar:3.6.0:compile - version managed from 8.5.1; omitted for duplicate)
as shown above the dependency mgnl-core contains the lucene-core v3.6 from jackrabbit-core 2.20.0
if i try to to exclude lucene v3.6 and only include that one from elasticsearch v7.8 with the following pom changes at my test module above :
<dependencies>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-rendering</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.8.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.8.0</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
and the following exception will happen :
java.lang.IllegalAccessError: class org.apache.jackrabbit.core.query.lucene.JackrabbitAnalyzer tried to access protected method org.apache.lucene.analysis.StopwordAnalyzerBase.<init>(Lorg/apache/lucene/util/Version;Ljava/util/Set;)V (org.apache.jackrabbit.core.query.lucene.JackrabbitAnalyzer and org.apache.lucene.analysis.StopwordAnalyzerBase are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @479f2dc2)
at org.apache.jackrabbit.core.query.lucene.JackrabbitAnalyzer.<clinit>(JackrabbitAnalyzer.java:46) ~[jackrabbit-core-2.20.0.jar:2.20.0]
at org.apache.jackrabbit.core.query.lucene.SearchIndex.<init>(SearchIndex.java:232) ~[jackrabbit-core-2.20.0.jar:2.20.0]
at info.magnolia.jackrabbit.lucene.SearchIndex.<init>(SearchIndex.java:67) ~[magnolia-core-6.2.2.jar:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.__newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45009) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45012) ~[?:?]
at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]
at java.lang.Class.newInstance(Class.java:584) ~[?:?]
after reading some threads i noticed that this happen due to the standart configuration of mgnl repo conf with jackrabbit @h2 db : jackrabbit-bundle-h2-search.xml that setup the searchindex of the jcr repositories that used jackrabbit's searchindex @org.apache.jackrabbit.core.query.lucene.SearchIndex
i spend a lot of time to fix that without disabling the Searchindex. Does anybody has an idea how to fix that to run magnolia 6.2.x with the new Rest-High-Level-Client of Elastic ?
greetings so long, hope anybody can help
p.s: for the archetype generation @example i used the following command to setup :
mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/
专注分享java语言的经验与见解,让所有开发者获益!
评论