ES--curl的一些操作命令

本文介绍如何使用CURL命令创建Elasticsearch索引,并详细展示了不同版本的配置语法,包括设置索引参数、定义映射及字段类型等。此外还提供了常用的查看和管理索引的命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 创建索引
--7.x 
curl -XPUT 'localhost:9205/st_workerattendance_ds' -d 
'{
  "settings": {
    "refresh_interval" : "60s",
    "number_of_shards": 1, 
    "number_of_replicas": 1 
  },
  "mappings" : {
	"doc": {
		  "properties" : {
			"@version" : {
			  "type" : "keyword"
			},
			"InDate" : {
			  "type" : "date",
			  "ignore_malformed": true,
			  "null_value": 20990101000000,
			  "format": "yyyy-MM-dd HH:mm:ss||epoch_millis||strict_date_optional_time||yyyyMMdd||yyyy-MM-dd"
			},
			"EditUserName" : {
			  "type" : "keyword"
			}
		
		  }
		}
	}
}'


--6.x以下 如在window 中 需加双引号 修改

curl -H "Content-Type: application/json" -u elastic:G05EgtzTvd -XPUT  121.40.57.159:8009/hw-qx-attendances-statics-2020-10month -d "{""settings"":{""refresh_interval"":""60s"",""number_of_shards"":1,""number_of_replicas"":1},""mappings"":{""doc"":{""properties"":{""Id"":{""type"":""long""},""Idcardno"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""InRecordHour"":{""type"":""long""},""InRecordMinute"":{""type"":""long""},""InSn"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""InsertTime"":{""type"":""date""},""IsUpload"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""OutRecordHour"":{""type"":""long""},""OutRecordMinute"":{""type"":""long""},""OutSn"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""ProjectId"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""RealName"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""RecordDate"":{""type"":""date""},""Sn"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""Worktime"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""WorktimeTransition"":{""type"":""keyword"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}}}}}}"


"format": "yyyy-MM-dd HH:mm:ss||epoch_millis||yyyyMMdd||yyyy-MM-dd"

# 查看mappings
curl -XGET 'localhost:9205/st_workerattendance_ds/_mappings?pretty'
# 查看 settings
curl -XGET 'localhost:9205/st_workerattendance_ds/_settings?pretty'

# 删除索引
curl -XDELETE 'localhost:9205/st_workerattendance_ds'

# 删除 添加 别名
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "hw-project-laboure-statistics-2021",
        "alias": "hw-project-laboure-statistics-month-alias"
      }
    },
    {
      "add": {
          "index": "hw-project-laboure-statistics-2021",
        "alias": "hw-project-laboure-statistics-month-alias"
      }
    }
  ]
}


  ** ?v 打印出表头信息
  ** ?pretty 美化输出
  • _cat
查看具体命令 curl localhost:9200/_cat
  1.集群健康状态 /_cat/health 
  2.资源信息 /_cat/allocation
  3.查看文档总数 /_cat/count
  4.查看具体索引的文档总数 /_cat/count/{index}
  5.查看fielddata占用内存情况(查询时es会把fielddata信息load进内存) /_cat/fielddata
  6.针对某一字段进行查看 /_cat/fielddata/{fields}
  7.查看数据恢复状态 /_cat/recovery
  8.查看具体索引的数据恢复状态 /_cat/recovery/{index}
  9.查看存储片段信息 /_cat/segments
  10.查看具体索引的存储片段信息 /_cat/segments/{index}
  11.查看节点状态 /_cat/nodes
  12.查看别名信息 /_cat/aliases
  13.指定别名查看信息 /_cat/aliases/{alias}
  14.查看线程池信息 /_cat/thread_pool
  15.查看线程池下插件 /_cat/thread_pool/{thread_pools}/_cat/plugins
  16.查看主节点 /_cat/master
  17.查看快照库 /_cat/snapshots/{repository}
  18.查看模板 /_cat/templates
  19.查看存储库 /_cat/repositories
  20.查看索引信息 /_cat/indices
  21.查看具体索引信息 /_cat/indices/{index}
  22.查看任务 /_cat/tasks
  23.查看待处理任务 /_cat/pending_tasks
  24.查看分片信息 /_cat/shards
  25.查看具体索引的分片信息 /_cat/shards/{index}
  26.查看节点的自定义属性 /_cat/nodeattrs
  27.查看插件信息 /_cat/plugins
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值