1.查询集群的基本运行状况-health
curl -XGET 'localhost:9200/_cat/health?v&pretty'
结果:
结果参数:
status:
- Green - everything is good (cluster is fully functional)
- Yellow - all data is available but some replicas are not yet allocated (cluster is fully functional)
- Red - some data is not available for whatever reason (cluster is partially functional)
2.集群的节点信息
curl -XGET 'localhost:9200/_cat/nodes?v&pretty'
结果:
说明此时我们的集群只有一个名字为“node-1”的节点
3.集群 中的索引信息
curl -XGET 'localhost:9200/_cat/indices?v&pretty'
结果:
说明:我们集群中还没有建立index
说明:我们集群中有一个customer的index
4.查看插件安装是否成功:
结果:
5.创建index 和mapping
如下:直接创建了index和mapping(这个mapping是结构化的映射)
{
"mapping":{
"blogpost":{
"properties":{
"msg":{"type":"string","index":"not_analyzed"},
"code":{"type":"integer","index":"not_analyzed"},
"count":{"type":"integer","index":"not_analyzed"},
"data":{
"type":"nested",
"properties":{
"type":{"type":"string","index":"not_analyzed"},
"user_name":{"type":"string","index":"not_analyzed"}
}
}
}
}
}
添加数据:
{"index":{"_index":"my_index","_type":"blogpost"}}
{"msg": "one","code": "00l","data": [{"type": "oracle", "user_name": "oracle2"},{"type": "mysql","user_name":"hive"}],"count": 1}
{"index":{"_index":"my_index","_type":"blogpost"}}
{"msg": "two","code": 0,"data": [{"type": "oracle", "user_name": "oracle2"},{"type": "mysql","user_name":"hive"}],"count": 2}
{"index":{"_index":"my_index","_type":"blogpost"}}
{"msg": "three","code": 0,"data": [{"type": "oracle", "user_name": "oracle2"},{"type": "mysql","user_name":"hive"}],"count": 3}
{"index":{"_index":"my_index","_type":"blogpost"}}
{"msg": "four","code": 0,"data": [{"type": "oracle", "user_name": "oracle2"},{"type": "mysql","user_name":"hive"}],"count": 4}
或者:
{"msg": "one","code": 0,"data": [{"type": "oracle", "user_name": "oracle2"},{"type": "mysql","user_name":"hive"}],"count": 1}
6.查看index下的type的mapping
7.ES Restful API GET、POST、PUT、DELETE、HEAD含义:
1)GET:获取请求对象的当前状态。
2)POST:改变对象的当前状态。
3)PUT:创建一个对象。
4)DELETE:销毁对象。
5)HEAD:请求获取对象的基础信息。