在ECK的Minikube本地集群中,如何最简手动添加Elasticsearch测试数据集?
为ECK部署的Elasticsearch手动添加测试数据集的最简方法
1. 获取Elasticsearch访问密码
ECK默认会为elastic用户生成密码并存储在对应Secret中,执行以下命令提取密码:
kubectl get secret es-qs-es-elastic-user -o=jsonpath='{.data.elastic}' | base64 --decode
记录该密码,后续访问集群时需要使用。
2. 本地端口转发ES服务
在终端执行端口转发命令,将集群内的Elasticsearch服务映射到本地9200端口:
kubectl port-forward service/es-qs-es-http 9200:9200
保持该终端窗口处于运行状态,不要关闭。
3. 导入测试数据
提供两种极简的手动导入方式:
方式一:插入单条测试数据
使用curl直接向ES写入一条测试文档:
curl -u elastic:你的密码 -X PUT "http://localhost:9200/test_docs/_doc/1?pretty" -H 'Content-Type: application/json' -d' { "title": "测试文档", "content": "这是一条用于验证的测试数据", "tags": ["test", "demo"], "create_time": "2024-05-20T12:00:00Z" } '
方式二:批量插入多条数据
利用ES的Bulk API一次性导入多条测试数据:
curl -u elastic:你的密码 -X POST "http://localhost:9200/_bulk?pretty" -H 'Content-Type: application/json' -d' {"index": {"_index": "test_docs"}} {"title": "用户行为日志1", "action": "浏览", "user_id": "u001", "timestamp": "2024-05-20T10:00:00Z"} {"index": {"_index": "test_docs"}} {"title": "用户行为日志2", "action": "下单", "user_id": "u002", "timestamp": "2024-05-20T10:05:00Z"} {"index": {"_index": "test_docs"}} {"title": "用户行为日志3", "action": "支付", "user_id": "u001", "timestamp": "2024-05-20T10:06:00Z"} '
4. 验证数据导入结果
执行以下命令查看已导入的数据:
curl -u elastic:你的密码 "http://localhost:9200/test_docs/_search?pretty"
内容的提问来源于stack exchange,提问作者Cake
相关产品推荐
相关产品推荐

