ES命令汇总

一、集群管理

1、查看集群健康状态

curl -X GET "localhost:9200/_cat/health?v"

2、查看集群健康状态

curl -X GET "localhost:9200/_cluster/health?pretty"

3、查看集群中的节点

curl -X GET "localhost:9200/_cat/nodes?v"

4、列出当前所有的索引

curl -X GET "localhost:9200/_cat/indices?v"

5、创建索引

curl -X PUT "localhost:9200/customer?pretty"

6、删除索引

curl -X DELETE "localhost:9200/customer?pretty"

7、设置数据类型

curl -X PUT "localhost:9200/allcountry?pretty" -H "Content-Type:application/json" -d '
{
    "settings": {
        "index.number_of_replicas": 0
    },
    "mappings": {
        "country_info": {
            "properties": {
                "geonameid": {
                    "type": "long"
                },
                "name": {
                    "type": "text"
                },
                "latitude": {
                    "type": "double"
                },
                "longitude": {
                    "type": "double"
                },
                "population": {
                    "type": "long"
                }
            }
        }
    }
}'

二、数据管理

1、添加Document

curl -X PUT "localhost:9200/customer/customer_info/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "John Doe"
}
'

2、查询Document

curl -X GET "localhost:9200/customer/customer_info/1?pretty"

3、替换Document

curl -X PUT "localhost:9200/customer/customer_info/1?pretty" -H "Content-Type:application/json" -d '
{
   "name":"Milton"
}
'

4、更新Document

curl -X POST "localhost:9200/customer/customer_info/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
  "doc": { "name": "Apple" }
}
'

5、更新Document---添加新字段

curl -X POST "localhost:9200/customer/customer_info/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
  "doc": { "name": "Tom", "age": 20 }
}
'

6、更新Document---使用Scripts脚本更新

curl -X POST "localhost:9200/customer/customer_info/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
  "script" : "ctx._source.age += 5"
}
'

注意:ctx代表被更新的对象本身

7、删除Document

curl -X DELETE "localhost:9200/customer/customer_info/2?pretty"

三、批量处理

1、批量添加Document


                
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值