elasticsearch head安装与 spring集成elasticsearch常见问题整理

一. elasticsearch head安装常见问题


1.用head插件请求失败

{
"error": "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status": 406
}

解决方法:编辑 head 插件的 vendor.js 文件,将 application/x-www-form-urlencoded 改为 application/json;charset=UTF-8 (6886行和7574行)

global: true,
type: "GET",
//contentType: "application/x-www-form-urlencoded",
contentType: "application/json;charset=UTF-8"
processData: true,
async: true,

二. spring 集成 elasticsearch 常见问题

1.failed to get local cluster state for {#transport#-1}
解决方法:设置 client.transport.sniff 为 false

    <elasticsearch:transport-client id="client" cluster-nodes="XXXXXXXX:XX"
                                    cluster-name="elasticsearch-name" client-transport-sniff="false" />

    <bean name="elasticsearchTemplate"
          class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
        <constructor-arg name="client" ref="client" />
    </bean>

原因:设置client.transport.sniff为true是用来嗅探整个集群的状态,会把集群中的其他节点的ip地址自动添加到客户端中,这样做就不用手动的去设置集群中所有节点的IP地址。如果ES服务器监听使用的是内网服务器IP而访问使用的外网时。这时会导致无法连接到ES服务器。

2.NodeDisconnectedException[[][XXXXXXX][cluster:monitor/nodes/liveness] disconnected]
[elasticsearch[Ariann][generic][T#2]] [INFO ] org.elasticsearch.client.transport - [Ariann] failed to get node info for {#transport#-1}{XXXXX}XXXXX}, disconnecting…

elasticsearch log
java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.6.0]
at org.elasticsearch.transport.TcpTransport.ensureVersionCompatibility(TcpTransport.java:1475) ~[elasticsearch-6.4.1.jar:6.4.1]
at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1421) ~[elasticsearch-6.4.1.jar:6.4.1]
at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:64) ~[transport-netty4-6.4.1.jar:6.4.1]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) [netty-codec-4.1.16.Final.jar:4.1.16.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297) [netty-codec-4.1.16.Final.jar:4.1.16.Final]

解决方法:更改elasticsearch版本
原因:从不支持的版本接收到的消息:[2.0.0]最小兼容版本是:[5.6.0]

 <!-- elasticsearch -->
    <dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>6.4.1</version>
    </dependency>

    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>6.4.1</version>
    </dependency>

    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <version>6.4.1</version>
    </dependency>
    
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-elasticsearch</artifactId>
      <version>3.1.3.RELEASE</version>
    </dependency>
  1. org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier
    原因:包冲突

你可能感兴趣的:(elasticsearch)