ElasticSearch常用命令(ElastciSearch6.x/7.x)
带账号密码访问
curl -XGET -u admin:password 'http://192.168.100.11:9200/_license' // 查看证书类型,带密码访问
复制
无密码访问:
# 本文博客地址:https://blog.csdn.net/knight_zhou/article/details/103687510
http://192.168.100.11:9200/_xpack/license/start_basic?acknowledge=true //通过postman进行请求改为basic模式
curl 'IP:9200/_cat/health?v' // health
curl 'IP:9200/_cat/nodes?v' // node
curl -XDELETE 'k.cn:9200/xxoo?pretty' // delete index
curl -XGET 'http://k.cn:9200/test-blog/_settings' // 查询index的setting
curl -XGET 'http://k.cn:9200/test-blog/_mappings'。 // 查询index的mapping
POST kibana_sample_data_logs/_delete_by_query?refresh?{"query":{"match_all": {}}} // 删除索引下的所有数据
复制
创建索引
curl -XPUT '127.0.0.1:9200/ccdd?pretty' # 创建索引,默认是2个分片 一个副本
curl '127.0.0.1:9200/_cat/indices?v' #查询所有索引及数据大小
复制
向指定索引新增文档:
curl -X PUT "localhost:9200/xxoo/_doc/1" -H 'Content-Type:application/json' -d' {
"user" : "tom",
"message" : "hello world"
}'
curl -X PUT "localhost:9200/xxoo/_doc/2" -H 'Content-Type:application/json' -d' {
"user" : "nick",
"message" : "你好"
}'
复制
查询文档
curl -XGET 127.0.0.1:9200/xxoo/_search |jq . # 查询索引下的全部文档
curl -XGET 127.0.0.1:9200/xxoo/_doc/1 |jq . # 根据id检索某个文档
curl -XGET 127.0.0.1:9200/xxoo/_search?q=user:tom|jq . # 条件查询
复制
更新文档(指定 _id
)
curl -X PUT "localhost:9200/xxoo/_doc/2" -H 'Content-Type:application/json' -d' {
"user" : "tom",
"message" : "hello world"
}'
复制
删除文档
curl -XDELETE 127.0.0.1:9200/xxoo/_doc/2 # 删除id为2的索引
复制
创建索引指定分片数和副本数
curl -XPUT 'http://k.cn:9200/studentindex' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}'
复制
查询索引是studentindex,type是student,studentname字段的值是“李”的信息
get查询:
curl -XGET 'http://k.cn:9200/studentindex/student/_search?q=studentname:李'
复制
post查询:
curl -X POST \
'http://localhost:9200/studentindex/student/_search' -d '{
"query": {
"match": {
"studentname": "李"
}
},
"from": 100, // 第几页开始
"size": 10 // 每页的大小
}'
复制
文章转载自DevOps运维技术栈,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年4月中国数据库流行度排行榜:OB高分复登顶,崖山稳驭撼十强
墨天轮编辑部
1348次阅读
2025-04-09 15:33:27
2025年3月国产数据库大事记
墨天轮编辑部
740次阅读
2025-04-03 15:21:16
2025年3月国产数据库中标情况一览:TDSQL大单622万、GaussDB大单581万……
通讯员
536次阅读
2025-04-10 15:35:48
征文大赛 |「码」上数据库—— KWDB 2025 创作者计划启动
KaiwuDB
459次阅读
2025-04-01 20:42:12
数据库,没有关税却有壁垒
多明戈教你玩狼人杀
410次阅读
2025-04-11 09:38:42
优炫数据库成功应用于国家电投集团青海海南州新能源电厂!
优炫软件
385次阅读
2025-03-21 10:34:08
最近我为什么不写评论国产数据库的文章了
白鳝的洞穴
317次阅读
2025-04-07 09:44:54
天津市政府数据库框采结果公布!
通讯员
316次阅读
2025-04-10 12:32:35
国产数据库需要扩大场景覆盖面才能在竞争中更有优势
白鳝的洞穴
277次阅读
2025-04-14 09:40:20
从HaloDB体验到国产数据库兼容性
多明戈教你玩狼人杀
268次阅读
2025-04-07 09:36:17