Elasticsearch OutOfMemoryError Java heap space

我正在运行一个8核,32g RAM弹性搜索节点,其中包含5个分片,4亿个(小)文档。

一切都很好,直到我运行agg搜索,然后分片开始失败:

java.lang.OutOfMemoryError: Java heap space

我用以下方式更改了堆大小:(也更改为相同)export ES_HEAP_SIZE=16gES_MAX_MEMES_MIN_MEM

还更改了弹性搜索的文件:yml

bootstrap.mlockall: true

甚至(由安装文档推荐):

sudo sysctl -w vm.max_map_count=262144

重新启动服务,仍然没有影响,仍然java.lang.OutOfMemoryError: Java heap space

还有其他建议吗?除了不运行 agg 查询?

查询为:

https://localhost:9200/my_index_name/_search?search_type=count
{
  "aggs": {
    "distinct_hostname": {
      "cardinality": {
        "field": "hostname"
      }
    }
  }
}

答案 1

我想我已经发现了这个错误。我使用“服务”来运行elasticsearch,因此我的环境变量被剥离了。我不得不用correcct env变量(特别是)更新文件。/etc/default/elasticsearchES_HEAP_SIZE=16g

到目前为止,它运行良好,应用程序没有出错。


答案 2

更新 Elasticsearch 5 的 Java 堆大小的正确方法是不使用 or 或使用命令行参数。据我所知,所有这些都被Elasticsearch安装目录中的配置文件覆盖。要更改这些设置,您需要编辑该文件中的这些行:EXPORT _JAVA_OPTIONSEXPORT ES_HEAP_SIZEconfig/jvm.options

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms2g
-Xmx2g

推荐