es常用命令

删除索引某个字段时间范围的数据

curl -XPOST "http://127.0.0.1:9200/event_log_hulianwang_v3/event_log_hulianwang_v3/_delete_by_query" -H 'Content-Type: application/json' -d'
{
"query": {
"range": {
"event_time": {
"gte": "2024-05-28 00:00:00",
"lte": "2024-05-28 23:59:59"
}
}
}
}'

 

 

###################索引index#################
#创建索引
PUT /demo
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
}
}

#查看指定索引
GET /demo

#查询ES中索引情况
GET /_cat/indices?v

curl -XGET "http://127.0.0.1:9200/_cat/indices?v"

#删除索引等同于删库跑路,请谨慎操作
DELETE /demo

#创建Type,同时定义映射Mapping字段及类型(需要先创建索引)
PUT demo/_mapping/example_type
{
"properties": {
"created":{
"type": "date"
},
"message":{
"type": "keyword"
}
}
}

#创建索引的同时创建Type并定义Mapping
PUT /demo
{
"mappings": {
"example_type":{
"properties": {
"created":{
"type": "date"
},
"message":{
"type": "keyword"
}
}
}
}
}

#添加别名
PUT /index_name/_alias/alias_name

##############文档Document######################

#插入文档
#系统定义 _id
POST /demo/example_type
{
"created":156113545900,
"message":"test1"
}

#查询文档
GET /demo/example_type/_search

#修改文档(根据_id)
POST /demo/example_type/m4FQWXkBEQiTdsynNel2/_update
{
"doc":{
"message":"updated"
}
}

#删除文档(根据_id)
DELETE /demo/example_type/moFMWXkBEQiTdsynyena


###############分词器##########################

#指定分词器以及字符串查看分词结果
POST /_analyze
{
"analyzer": "standard",
"text": "hello world"
}

POST /_analyze
{
"analyzer": "standard",
"text": "学生"
}

POST /_analyze
{
"analyzer": "ik_smart",
"text":"小米手机"
}


#1.创建word索引
PUT /word

#创建analyzer_demo类型并定义映射Mapping
PUT /word/analyzer_demo/_mapping
{
"properties": {
"name":{
"type": "text",
"analyzer": "ik_smart"
}
}
}


##删除索引里的全部数据
POST dial_test_task_info/dial_test_task_info/_delete_by_query
{
"query": {
"match_all": {}
}
}


#批量更新
POST event_log/event_log/_update_by_query
{
"script": {
"source": "ctx._source['event_type'] = '设备CPU负荷异常'"
},
"query": {
"bool": {
"must": [
{
"term": {
"event_type.keyword": {
"value": "/device_status/cpu_abnorma"
}
}
}
]
}
}
}

##删除没有group_id的数据
POST event_log/event_log/_delete_by_query
{
"query": {
"bool": {
"must": [
{
"term": {
"event_type.keyword": {
"value": "应用拨测"
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "group_id"
}
}
]
}
}
]
}
}
}

#删除别名
POST /_aliases
{

"actions": [

{"remove": {"index": "event_log_zhongxin_2024050*", "alias": "event_log_zhongxin"}}

]

}

posted on 2024-06-06 16:43  代码吴彦祖  阅读(2)  评论(0编辑  收藏  举报