elasticsearch常见的问题

环境配置

  • ES版本:5.4.3
  • 系统:CentOS release 6.x
  • spring-data-elasticsearch:3.0.0.RELEASE
  • spring:5.0.1.RELEASE

问题

1.本地访问es的restful接口不通

需要更改下面配置(elasticsearch.yml):

network.bind_host:0.0.0.0
network.host: <服务器ip>

如果系统是CentOS release 6.x的,需要在(elasticsearch.yml)增加下面语句

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

2.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

需要修改linux的内核设置,在/etc/sysctl.conf文件加入

vm.max_map_count=262144

然后系统执行:

sysctl -p

3.availableProcessors is already set to

Caused by: java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]
    at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:51)
    at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
    at org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:82)
    at org.elasticsearch.transport.netty4.Netty4Transport.<init>(Netty4Transport.java:138)
    at org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$0(Netty4Plugin.java:93)
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:174)
    at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:265)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:130)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:116)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:106)
    at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.buildClient(TransportClientFactoryBean.java:91)
    at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.afterPropertiesSet(TransportClientFactoryBean.java:86)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1763)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1700)
    ... 82 more

解决办法:

@Slf4j
@Component
public class ElasticSearchConfiguration implements InitializingBean {

    static {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("*****************es_config*************************");
        log.info("es.set.netty.runtime.available.processors:{}", System.getProperty("es.set.netty.runtime.available.processors"));
        log.info("***************************************************");
    }
}

原因是Lucene改进了数值类型的索引数据结构,使用了block k-d 树。这种树的叶结点上文档不是有序排列的,所以查询的时候需要获取所有的文档id,访问 docValues构造 bitset,进行其它条件的联合查询。当查询的结果集很大的时候,大量时间会用于构造bitset,导致了慢查询。

解决方式:在不需要进行 rangeQuery 的时候,尽量不要选择数值类型作为存储格式,使用 keyword 替代,尤其是在重复值数量很大的时候。

https://elasticsearch.cn/article/446

推荐阅读更多精彩内容