You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch创建索引超时求助(8.11.3版本Windows10环境)

Elasticsearch 8.11.3 创建索引超时问题排查方案

问题背景

Windows10环境下部署Elasticsearch 8.11.3与Kibana 8.11.3,可正常访问http://localhost:9200/和http://localhost:5601/,集群健康状态显示为green,但执行索引创建操作时,即使设置request_timeout=30仍触发超时错误。

提供的信息

1. Python代码

import os
import sys
import pandas as pd 
from elasticsearch import Elasticsearch
def connect_database():
    es = None
    es = Elasticsearch([{'host': 'localhost', 'port': 9200, 'scheme': 'http'}])
    if es.ping():
        print("Elastic search connected")
        print(es.cluster.health())

    else:
        print("Connect failed")
    return es

es = connect_database()
es.indices.create(index="mydatabasename", ignore=400, request_timeout=30)

2. 运行输出

Elastic search connected
{'cluster_name': 'elasticsearch', 'status': 'green', 'timed_out': False, 'number_of_nodes': 1, 'number_of_data_nodes': 1, 'active_primary_shards': 29, 'active_shards': 29, 'relocating_shards': 0, 'initializing_shards': 0, 'unassigned_shards': 0, 'delayed_unassigned_shards': 0, 'number_of_pending_tasks': 13, 'number_of_in_flight_fetch': 0, 'task_max_waiting_in_queue_millis': 3050137, 'active_shards_percent_as_number': 100.0}

---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
File ~\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py:449, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    445         except BaseException as e:
    446             # Remove the TypeError from the exception chain in
    447             # Python 3 (including for exceptions like SystemExit).
    448             # Otherwise it looks like a bug in the code.
--> 449             six.raise_from(e, None)
    450 except (SocketTimeout, BaseSSLError, SocketError) as e:

File <string>:3, in raise_from(value, from_value)

File ~\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py:444, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    443 try:
--> 444     httplib_response = conn.getresponse()
    445 except BaseException as e:
    446     # Remove the TypeError from the exception chain in
    447     # Python 3 (including for exceptions like SystemExit).
    448     # Otherwise it looks like a bug in the code.

File c:\Program Files\Python310\lib\http\client.py:1374, in HTTPConnection.getresponse(self)
   1373 try:
--> 1374     response.begin()
   1375 except ConnectionError:
...
--> 261         raise ConnectionTimeout("TIMEOUT", str(e), e)
    262     raise ConnectionError("N/A", str(e), e)
    264 # raise warnings if any from the 'Warnings' header.

ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='localhost', port=9200): Read timed out. (read timeout=30))

3. elasticsearch.yml配置

# Enable security features
xpack.security.enabled: false

xpack.security.enrollment.enabled: false

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: false
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["MSI"]

# Allow HTTP API connections from anywhere
# Connections are encrypted and require user authentication
http.host: 0.0.0.0

排查与解决步骤

  1. 优先处理任务堆积问题
    从集群健康数据可见,number_of_pending_tasks=13且task_max_waiting_in_queue_millis=3050137(约50分钟),说明ES节点任务队列严重阻塞,新请求无法及时响应:

    • 停止ES服务,备份data目录后清空该目录,重启节点。
    • 检查Windows系统资源,确保CPU、内存未被其他进程耗尽。修改config/jvm.options调整ES堆内存,例如设置-Xms4g -Xmx4g(根据机器配置调整,建议不超过物理内存的50%)。
  2. 优化Python客户端配置
    调整客户端连接参数,增加超时时间、重试机制和连接数:

    es = Elasticsearch(
        [{'host': 'localhost', 'port': 9200, 'scheme': 'http'}],
        request_timeout=60,
        connections_per_node=5,
        retry_on_timeout=True,
        max_retries=3
    )
    
  3. 验证索引创建的可行性
    通过Kibana Dev Tools执行以下命令,直接在ES节点创建索引:

    PUT /mydatabasename
    {}
    
    • 若该操作成功,问题出在Python客户端配置;若同样超时,需聚焦ES节点性能优化。
  4. 查看并清理阻塞任务
    访问http://localhost:9200/_cat/tasks?v查看当前运行的任务,识别长时间阻塞的任务,通过/_tasks/{task_id}/_cancel接口终止(操作前确认任务无业务影响)。

内容的提问来源于stack exchange,提问作者Nguyễn Quốc Nhật Minh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 01:25:06