查询所有es里的索引
GET _cat/indices
查询
# 查询
GET index名/_search
条件匹配
GET index名/_search
{
"query": {
"match": {
"id":123
}
}
}
多字段查询:
GET index名/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "张三"
}
},
{
"match": {
"age": "22"
}
}
]
}
}
}
GET index名/_search
{
"query": {
"bool": {
"must": {
"match":{
"id":"123"
}
},
"filter": {
"range": {
"addTime": {
"gte": "2022-02-22 00:00:00",
"lte": "2022-02-24 23:59:59"
}
}
}
}
}
}
条件删除
POST / index名/_delete_by_query?slices=auto&conflicts=proceed&wait_for_completion=false
{
"query":{
"bool":{
"must": [
{
"range":{
"addTime":{
"from":"2023-07-01 00:00:00",
"to":"2023-07-03 23:59:59"
}
}
}
]
}
}
}
计数
GET index名/_count
sql 查询
GET _sql?format=json
{
"query": "SELECT * FROM index名"
}
设置最大可显示数据量
PUT _all/_settings
{
"index.max_result_window":1000000
}
重命名索引(拷贝)
POST _reindex
{
"source": {
"index": "源索引"
},
"dest": {
"index": "新索引"
}
}
清理索引缓存
POST index名/_cache/clear
增加字段
PUT /index名/_mapping
{
"properties": {
"字段名": {
"type": "keyword" //类型
}
}
}
条件删除数据
POST /index/_delete_by_query?slices=auto&conflicts=proceed&wait_for_completion=false
{
"query": {
"bool": {
"must": [
{
"range": {
"time": {
"from": "2023-09-27 11:00:00",
"to": "2023-09-27 23:59:59"
}
}
}
]
}
}
}
往新索引中写入旧索引条件范围内的数据,修改某个字段值
POST _reindex?slices=6&refresh
{
"source": {
"index": "旧索引",
"query": {
"bool": {
"must": [
{
"range": {
"time": {
"from": "2023-09-01 00:00:00",
"to": "2023-09-06 23:59:59"
}
}
}
]
}
}
},
"dest": {
"index": "新索引"
},
"script": {
"source": "ctx._id='ABC'+ctx._id;ctx._source.字段名='ABC'+ctx._source.字段名"
}
}
查看节点
GET _cat/nodes?v
查看执行中的任务
GET _tasks
结束某个任务
POST /_tasks/31rgRai2TiGhh5wEH4ngug:49752268/_cancel