一、集群管理
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