Elasticsearch 创建index库 timeout

文章描述了一个用户在使用Python客户端尝试创建Elasticsearch索引时遇到的问题,报错与磁盘空间不足有关。通过调整Kibana中的ES磁盘设置并解决JVM内存问题,解决了创建索引失败的问题。
摘要由CSDN通过智能技术生成

问题概述

  1. 使用 python 客户端 代码进行创建,【之前成功创建,但是现在出现报错,报错代码es_connection.client.indices.create

def create_vector_index(dataset_index_name,vector_query_field,query_field):

    es_connection = get_collention(dataset_index_name,vector_query_field,query_field)
    
    es_connection.client.indices.create(
    index=dataset_index_name,
    mappings={
        "properties": {
            f"{query_field}": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart",    
                 "fields": {
                        "raw": { 
                        "type":  "keyword"
                                }
                            }                      
                               },
            f"{vector_query_field}": {
                        "type": "dense_vector",
                        "dims": 1024,
                        "index": True,
                        "similarity": "cosine",
                    },
        }
    },
    )
  1. 重启 es01 docker 容器 ,同样出现 上述问题。
  2. 使用kibana 进行 调取 es库中数据可以正常使用,也可正常链接。 但是同样不能创建 index库。请求超时错误。
  1. 通过步骤3,断定es出了问题,查看docker日志 ,docker logs -f es01, 开始警告磁盘空间,【问题很可能出在 es 存储上限,导致库不能创建成功】

创建库失败时,打印的日志,排除网络问题导致的超时。

【解决方法】

kibana 客户端 设置es的磁盘上限

PUT _cluster/settings
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "95%",
    "cluster.routing.allocation.disk.watermark.high": "95%"
  }
}

返回结果:

{
  "acknowledged": true,
  "persistent": {},
  "transient": {
    "cluster": {
      "routing": {
        "allocation": {
          "disk": {
            "watermark": {
              "low": "95%",
              "high": "95%"
            }
          }
        }
      }
    }
  }
}

执行上面命令后,查看日志可以看到,存储下限进行调整,另外可以发现,在kibana 的 红色的ir_quest的库 自动变为黄色,可以正常使用。

  1. 进入es01 容器,查看gc.log, 发现另一个问题:【一直gc清理,但清理不出太多空间, 说明JVM 空间 当时启动docker 时设置太小。】

附加问题的解决方法是: 在启动docker的es01时的启动命令有问题:

【ps小工具】查看docker的启动参数工具, python环境, 执行: pip install runlike

runlike -p es01

原始命令:

(fastapi) (base) server@server:~/data3/chat_fastapi_project/information_retrieval$ runlike -p es01 
docker run --name=es01 \\
        --hostname=d989639e3cb4 \\
        --user=1000:0 \\
        --network=elastic \\
        --workdir=/usr/share/elasticsearch \\
        -p 9200:9200 \\
        --expose=9300 \\
        --restart=no \\
        --runtime=runc \\
        --memory="1073741824" \\
        -t \\
        docker.elastic.co/elasticsearch/elasticsearch:8.11.3 \\
        eswrapper

更新的参考命令:

sudo docker run --name elasticsearch \\
-p 9200:9200  -p 9300:9300 \\
--restart=always \\
--privileged=true \\
-it -v /etc/localtime:/etc/localtime:ro \\
-e "discovery.type=single-node" \\
-e ES_JAVA_OPTS="-Xms1024m -Xmx8192m" \\
-v /opt/elasticsearch/config:/usr/share/elasticsearch/config \\
-v /opt/elasticsearch/data:/usr/share/elasticsearch/data \\
-v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins \\
-v /opt/elasticsearch/logs:/usr/share/elasticsearch/logs \\
-d elasticsearch:8.11.3 \\

【ps小技巧】后面在创建ES 容器时, 先创建一次, 将默认的生成的这些文件copy出来, 然后 删除 容器, 在重新启动,启动时将关键目录挂载到镜像中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瑾怀轩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值