ElasticSearch 常用命令大全
创始人
2025-05-29 10:16:50
0

1、获取索引列表

GET /_cat/indices?format=json&index=[索引名称,可使用通配符]

2、别名操作

GET /_alias/20*

POST /_aliases

{

"actions": [

{

"add": {

"alias": "logs_current",

"index": "logs_2018-10"

}

},

{

"remove": {

"alias": "logs_current",

"index": "logs_2018-09"

}

},

{

"add": {

"alias": "last_3_months",

"index": "logs_2018-10"

}

},

{

"remove": {

"alias": "last_3_months",

"index": "logs_2018-07"

}

}

]

}

3、索引操作

https://www.cnblogs.com/bensonwei/p/12616480.html

https://www.cnblogs.com/quanxiaoha/p/11532487.html

创建

PUT /index_name

{ "settings": { "number_of_shards": 3, "number_of_replicas": 1 } }

Response:

{ "acknowledged" : true, "shards_acknowledged" : true }

POST /_reindex?wait_for_completion=false

{

  "source": {

    "index": "nba"

  },

  "dest": {

    "index": "nba_20200202"

  }

}

---------------------------------------------------------------------------------------------------------------

4、查询操作

https://www.cnblogs.com/cjsblog/p/10120470.html

模糊匹配

模糊匹配查询 | Elasticsearch: 权威指南 | Elastic

排序

Elasticsearch查询——Sort(查询排序)_elasticsearch sort排序_大·风的博客-CSDN博客

5、任务管理

使用Task API获取所有运行的reindex请求的状态:

GET _tasks?detailed=true&actions=*reindex

根据id直接查找任务:

GET /_tasks/taskId:1

取消任务

POST _tasks/task_id:1/_cancel

更改requests_per_second参数的值:

POST _reindex/task_id:1/_rethrottle?requests_per_second=-1

6.最大行数设置

put /index/_settings

{“max_result_window”:“1000000”}

然后get查看是否生效

7.修改密码

http请求需要设置Authorization:Basic base64 encode(elastic:容器设置的密码 )

以curl -XPUT --user elastic:容器设置的密码 'http://127.0.0.1:9201/_xpack/security/user/username/_password' -H "Content-Type:application/json" -d '{ "password" : "111111" }'

8.索引更新

curl -XPUT 'http://localhost:9200/myindex/_settings' -H 'Content-Type: application/json' -d '

{

"index" : {

"number_of_replicas" : 0

}

}

9.索引迁移

创建新索引

PUT log_car_milage_1

修改map

POST /log_car_milage_1/_mapping
{"properties" : {"deviceId" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"device_id" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"distance" : {"type" : "long"},"milage" : {"type" : "long"},"timestamp" : {"type" : "date"}}
}

从旧索引导入数据到新索引

POST _reindex
{"source": {"index": "log_car_milage"},"dest": {"index": "log_car_milage_1",}
}

删除旧索引

DELETE /log_car_milage

给新索引添加别名(旧索引的名称)

POST /_aliases
{"actions": [{ "add": {"alias": "log_car_milage","index": "log_car_milage_1"}}]
}

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...