1.elasticserach API 操作
• elasticsearch rest api遵循的格式为:curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>
• 检查es版本信息:http://IP:9200
• 查看集群是否健康:http://IP:9200/_cat/health?v
• 查看节点列表:http://IP:9200/_cat/nodes?v
• 列出所有索引及存储大小:http://IP:9200/_cat/indices?v
• 创建索引:curl -XPUT 'IP:9200/XX?pretty
2.elasticserach操作
2.1 基本概念
• Index:索引(库)
• Type:索引中的数据类型(表)
• Document:文档对象(数据行row)
• Field:字段,文档的属性(数据列)
• Query DSL:查询语法(sql)
2.2 文档操作
2.2.1 创建文档
• 请求:
POST /elasticsearch/student/1
{
"name":"zhangsan",
"clazz":"0115bigdata",
"description":"we are family"
}
• 返回:
{
"_index": "elasticsearch",
"_type": "student",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
2.2.2 获取文档
• 请求:
GET elasticsearch/student/1
• 返回:
{
"_index": "elasticsearch",
"_type": "student",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "zhangsan",
"clazz": "0115bigdata",
"description": "we are family"
}
}
2.2.3 更新文档
• 请求:
POST /elasticsearch/student/1/_update
{
"doc":{
"description":"hello world"
}
}
• 返回:
{
"_index": "elasticsearch",
"_type": "student",
"_id": "1",
"_version": 4,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1
}
2.2.4 删除文档
• 请求:
DELETE elasticsearch/student/1
• 查询结果:
{
"_index": "elasticsearch",
"_type": "student",
"_id": "1",
"found": false
}