Elasticsearch - 升级到2.1.1后搜索失败

时间:2016-01-22 11:17:12

标签: java java-ee elasticsearch wildfly

我正在使用嵌入式Elasticsearch开发Java EE 7 WebApplication(在wildfly 10中运行)。 升级到elasticsearch 2.1.1后搜索不再有效。 (索引似乎有效)

有效的依赖关系:

public static void ProcessData<T>(string Group, int Id)
{
   string ConnectionString = "SomeConnectionStringName";
   string sql = "select top 1 * from " + (typeof (T).Name) + " where " + Group + "Id = " + Id + ";";             
   DbContext d = new DbContext(ConnectionString);
   var data =  d.Database.SqlQuery<T> (sql).First();
   //Do some stuff with the data...
   html = "some tekst...";
   foreach (var sourceProperty in data.GetType().GetProperties())
   {
    html = html.Replace("{#" + sourceProperty.Name + "#}",    sourceProperty.GetValue(data, new object[] { }) == null ? "" : sourceProperty.GetValue(data, new object[] { }).ToString());
    //enter code here

   }
}

升级的依赖项:

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>5.2.1</version>
    </dependency>

索引一个非常基本的文档(索引似乎工作)后,搜索失败,出现以下异常:

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>5.3.1</version>
    </dependency>

这就是我的搜索结果:

org.elasticsearch.action.search.SearchPhaseExecutionException : all shards failed [Proxied because : Original exception caused: class java.io.NotSerializableException: org.elasticsearch.action.search.ShardSearchFailure]
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:228)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:174)
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)
at org.elasticsearch.transport.local.LocalTransport.handleException(LocalTransport.java:354)
at org.elasticsearch.transport.local.LocalTransport.handlerResponseError(LocalTransport.java:345)
at org.elasticsearch.transport.local.LocalTransport.messageReceived(LocalTransport.java:241)
at org.elasticsearch.transport.local.LocalTransportChannel$2.run(LocalTransportChannel.java:99)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: _byteSymbolCanonicalizer
at com.fasterxml.jackson.dataformat.smile.SmileFactory._createParser(SmileFactory.java:404)
at com.fasterxml.jackson.dataformat.smile.SmileFactory.createParser(SmileFactory.java:327)
at org.elasticsearch.common.xcontent.smile.SmileXContent.createParser(SmileXContent.java:107)
at org.elasticsearch.common.xcontent.smile.SmileXContent.createParser(SmileXContent.java:113)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:817)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:651)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:617)
at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:262)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
at org.elasticsearch.transport.local.LocalTransport$2.doRun(LocalTransport.java:280)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

我通过着色elasticsearch依赖项来解决这个问题

1。我创建了一个单独的maven模块:

<project>
...
<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.3.4</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <relocations>
                            <relocation>
                                <pattern>com.fasterxml.jackson</pattern>
                                <shadedPattern>shaded.elasticsearch.jackson</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
...
</project>

2。然后在我的主项目中使用该模块作为依赖项

    <dependency>
        <groupId>drivve</groupId>
        <artifactId>elasticsearch-shaded</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>5.5.0</version><!-- be sure to match the version required by elasticsearch-shaded -->
    </dependency>

现在一切正常,并没有那么难以管理。 有关着色es依赖项的更多信息可以在std::shared_ptr找到。