当前位置: 首页 > news >正文

es 常用命令(已亲测)

说明: elastic:1235  账号:密码

           _isShare : 字段

1、 根据一个参数查询es

curl -XGET -u  elastic:1235   'http://10.223.73.3:9200/catalog/_search' \
-H 'Content-Type: application/json' \
-d '{"query":{"match":{"_isShare":{"query":"1"}}}}';

curl -XGET -u elastic:1235 'http://10.28.72.2:9200/catalog/_search' \
-H 'Content-Type: application/json' \
-d '{"query":{"term":{"cataId":"d422646cb4e9450e819893b86042ab5f"}}}';

2、根据Id 删除数据

curl -X DELETE   -u elastic:1235 http://10.225.74.56:9200/95213405963d495582ac7ca34ea12869
3、超过10000条后多次查询


curl -XGET -u elastic:1235 'http://10.28.71.3:9200/catalog/_search?scroll=3m' \
-H 'Content-Type: application/json' \
-d '{"size":10000,"query":{"match_all":{}},"_source":["cataId"]}'  >> 20240529scoll.txt
获取到:scroll_id

curl -XGET -u elastic:1235 'http://10.21.7.13:9200/_search/scroll' \
-H 'Content-Type: application/json' \
-d '{"scroll_id":"DXF1ZXJ5QW5kRmV0Y2gBAAAAAAA-WxYWZTNIVldDSWFSTTZJTml5b0lkM0FmQQ==","scroll":"3m"}' >> 20240529scoll.txt ;

4、 es 数据格式化,只获取cataid
cat 20240904001.txt | jq '.hits.hits[]._source.cataId | .cataTitle'  >> 20240904002.txt

5、去掉双引号

sed -i 's/\"/''/g' 20241023161.txt

6、 多个字段获取拼接
cat 20240904001.txt | jq -r '.hits.hits[] | [._source.cataTitle,._source.cataId,._id ] | join(",")'  >> 20240904002all.txt

7、 一个字段多个值查询


curl -XGET -u elastic:1235 'http://10.225.74.56:9200/catalog/_search' \
-H 'Content-Type: application/json' \
-d '{"size":10000,"query":{"match":{"groupId":["1d02a1d6ee144956b0e2502a7bd491e6","784fa48e4623460185603bc4b13d4d25"]}}}' >> 2024102313.txt;
8、 既不等于也不等于


curl -XGET -u elastic:1235 'http://10.225.74.56:9200/catalog/_search' \
-H 'Content-Type: application/json' \
-d '{"size":10000,"query":{"bool":{"must_not":[{"term":{"groupId":"fed0d0bd09424d1ea7c4b402d9f7b4af"}},{"term":{"isShare":"2"}}]}}}' >> 2024102316.txt;
9、更新字段数据
curl -XPOST -u elastic:1235 'http://10.225.74.56:9200/catalog/_update/b7f2d49a-6b3e-4af4-be40-b3a0b61c1551' \
-H 'Content-Type: application/json' \
-d '{    "doc":{        "labelNameMH":"一次性"    }}' ;

10 、删除多个索引
curl -XDELETE -u elastic:1235 'http://10.220.71.3:9200/index_test0402,catalog_copy,test_m'

11 、 模糊搜索
curl -XGET -u elastic:1235 'http://10.225.71.153:9200/operatelog/_search' \
-H 'Content-Type: application/json' \
-d '{"size":10,"query":{"wildcard":{"createTime":"*2023*"}},"_source":["logId"]}';

12 、根据Id精确查询

curl -XGET -u elastic:1235 'http://10.225.74.56:9200/catalog/_search' \
-H 'Content-Type: application/json' \
-d '{"size":10,"query":{"term":{"cataId":"b7f2d49a-6b3e-4af4-be40-b3a0b61c1551"}}}'

13、查看索引文档个数
curl -XGET -u elastic:1235 'http://10.213.71.1:9200/operatelog/_count'

14、 创建只读角色
curl -XPOST -u elastic:1235 'http://10.145.71.1:9200/_security/role/read_all_indices' \
-H 'Content-Type: application/json' \
-d '{ "indices":[{"names":["*"],"privileges":["read"]}],"cluster":["monitor"]}'
-- 创建只读用户
curl -XPOST -u elastic:1235 'http://10.145.74.56:9200/_security/user/readSjzt' \
-H 'Content-Type: application/json' \
-d '{"password":"sjztRead@2024","roles":"read_all_indices"}'
-- 验证权限
curl -XPUT -u readSjzt:sjztRead@2024 http://10.145.74.56:9200/index_test0528
curl -XGET -u readSjzt:sjztRead@2024 'http://10.145.74.56:9200/catalog/_search'

15、创建索引
curl -XPUT -u elastic:1235 http://10.145.71.1:9200/test_m

16、 查看所有索引

  curl -XGET -u elastic:1235 http://10.145.71.1:9200/_cat/indices?v

http://www.lryc.cn/news/472757.html

相关文章:

  • RabbitMQ 高级特性——事务
  • HCIP-HarmonyOS Application Developer V1.0 笔记(二)
  • 初体验鸿蒙 HarmonyOS NEXT开发
  • MySQL---主从复制和读写分离
  • Apache Kyuubi概述——网易数帆(网易杭州研究院)开源
  • 前端代码注释
  • Linux线程安全(二)条件变量实现线程同步
  • Linux初阶——线程(Part2):互斥同步问题
  • 力扣——二叉树的后序遍历(C语言)
  • 利用kimi编程助手从0到1开始搭建小程序!
  • WSL(Ubuntu20.04)编译和安装DPDK
  • HLS协议之nginx-hls-多码率测试环境搭建
  • 函数式接口与回调函数实践
  • Windows11系统如何使用自带的录音、录屏工具?
  • 使用 web (vue 和DRF))实现 模拟一个IDE 功能思路
  • 智航船舶租赁综合管理系统
  • 统信UOS下启动图形界面应用工具monitor报JAVA相关错:An error has occurred. See the log file
  • N-154基于springboot酒店预订管理系统
  • 微信小程序如何实现地图轨迹回放?
  • vscode的一些使用心得
  • Python金色流星雨(完整代码)
  • [山河CTF 2024] week3
  • Java集合常见面试题总结(5)
  • 牛客网刷题(3)(Java的几种常用包)
  • PyTorch nn.Conv2d 空洞卷积
  • 像素、分辨率、PPI(像素密度)、帧率的概念
  • 两步GMM计算权重矩阵
  • leetcode452. 用最少数量的箭引爆气球
  • 【Android】使用TextView实现按钮开关代替Switch开关
  • (49)MATLAB实现迫零均衡器原理与代码