在这里插入图片描述
测试情况:
- 可以正常连上9202端口
host="127.0.0.1"
port=9202
from elasticsearch import Elasticsearch
import elasticsearch
es = Elasticsearch([{'host':host,'port':port,'scheme':'http'}])
# es = Elasticsearch('http://localhost:9202')
# print(es.ping())
mapping = {
"mappings": {
"properties": {
"path": {
"type": "keyword"
},
"en_description": {
"type": "text"
}
}
}
}
all_indexes = [index for index in es.indices.get_alias().keys() if not index.startswith('.')]
print(all_indexes)
es.indices.create(index="test_idx", body=mapping)
- 执行程序时,显示
elastic_transport.ConnectionTimeout: Connection timed out
执行es.ping()时也显示True
curl -X PUT "http://127.0.0.1:9202/test_index" -H 'Content-Type: application/json' -d'
{
"mappings": {
"properties": {
"vector_field": {
"type": "dense_vector",
"dims": 1536
},
"path": {
"type": "keyword"
},
"en_description": {
"type": "text"
},
"zh_description": {
"type": "text"
}
}
}
}'
{"error":{"root_cause":[{"type":"process_cluster_event_timeout_exception","reason":"failed to process cluster event (create-index [test_index], cause [api]) within 30s"}],"type":"process_cluster_event_timeout_exception","reason":"failed to process cluster event (create-index [test_index], cause [api]) within 30s"},"status":503}(.venv) (base) [hongjiayin@localhost video_clip]$
3.访问es健康状态
(.venv) (base) [@localhost video_clip]$ curl -X GET "http://127.0.0.1:9202/_cluster/health?pretty"
{
"cluster_name" : "docker-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 2,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 48408750,
"act
(.venv) (base) [@localhost video_clip]$ curl -X GET http://10.8.:9202/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1724652050 06:00:50 docker-cluster green 1 1 0 0 0 0 0 2 13.5h 100.0%
(.venv) (base) [hongjiayin@localhost video_clip]$
状态为green
- 查看es日志
sudo docker logs es
{"@timestamp":"2024-08-26T05:53:08.102Z", "log.level": "WARN", "message":"path: /test_idx, params: {index=test_idx}, status: 503", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"elasticsearch[121d71428054][generic][T#1]","log.logger":"rest.suppressed","elasticsearch.cluster.uuid":"8-PH0sSUSWCEQdBCkG1Iww","elasticsearch.node.id":"GwdDKVFPS1-fC1jVNeYy2Q","elasticsearch.node.name":"121d71428054","elasticsearch.cluster.name":"docker-cluster","error.type":"org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException","error.message":"failed to process cluster event (create-index [test_idx], cause [api]) within 30s","error.stack_trace":"org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException: failed to process cluster event (create-index [test_idx], cause [api]) within 30s\n\tat org.elasticsearch.server@8.14.3/org.elasticsearch.cluster.service.MasterService$TaskTimeoutHandler.doRun(MasterService.java:1490)\n\tat org.elasticsearch.server@8.14.3/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:984)\n\tat org.elasticsearch.server@8.14.3/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1570)\n"}
- 查看es集群的执行任务
$ curl -X GET http://127.0.0.1:9202/_cat/pending_tasks
316 13.5h URGENT update_tsdb_data_stream_end_times
315 13.5h HIGH cluster_reroute(disk threshold monitor)
参考:
https://gongxiude.gitbook.io/operation_notes/elk/eslasticsearch-shu-ju-bu-neng-xie-ru-wen-ti-pai-cha-chu-li
https://www.elastic.co/guide/en/elasticsearch/reference/7.3/cluster-stats.html
- 重启es
sudo docker restart es
重启后使用curl创建索引成功
$ curl -X PUT "http://127.0.0.1:9202/video_index" -H 'Content-Type: application/json' -d'
> {
> "mappings": {
> "properties": {
> "vector_field": {
> "type": "dense_vector",
> "dims": 1536
> },
> "path": {
> "type": "keyword"
> },
> "en_description": {
> "type": "text"
> },
> "zh_description": {
> "type": "text"
> }
> }
> }
> }' --max-time 120
{"acknowledged":true,"shards_acknowledged":false,"index":"video_index"}(base) [hongjiayin@localhost ~]$
运行python脚本
def es_test():
host="127.0.0.1"
port=9202
from elasticsearch import Elasticsearch
import elasticsearch
# es = Elasticsearch([{'host':host,'port':port,'scheme':'http'}])
es = Elasticsearch('http://localhost:9202')
print(es.ping())
print(es.info())
mapping = {
"mappings": {
"properties": {
"vector_field": {
"type": "dense_vector",
"dims": 1536
},
"path": {
"type": "keyword"
},
"en_description": {
"type": "text"
},
"zh_description": {
"type": "text"
}
}
}
}
all_indexes = [index for index in es.indices.get_alias().keys() if not index.startswith('.')]
print(all_indexes)
显示如下:
True
{'name': '121d71428054', 'cluster_name': 'docker-cluster', 'cluster_uuid': '8-PH0sSUSWCEQdBCkG1Iww', 'version': {'number': '8.14.3', 'build_flavor': 'default', 'build_type': 'docker', 'build_hash': 'd55f984299e0e88dee72ebd8255f7ff130859ad0', 'build_date': '2024-07-07T22:04:49.882652950Z', 'build_snapshot': False, 'lucene_version': '9.10.0', 'minimum_wire_compatibility_version': '7.17.0', 'minimum_index_compatibility_version': '7.0.0'}, 'tagline': 'You Know, for Search'}
['video_index', 'test_idx', 'test_index']
重启后再次查看es状态
curl -X GET http://127.0.0.1:9202/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent