1. 新增文档
格式:PUT /index/type/1
在es6.x版本后,就不推荐使用type了。可以使用_doc替代type。
PUT /person/_doc/1{"name":"john","age":10,"born":"2010-12-01","tags":["boy","sunny"]}
es会自动建立index和type,而且es还会为每个字段创建倒排索引,可以让其被搜索到。
2. 查询文档
格式:GET /index/_search 或者 GET /index/_dodc/id
查询结果:
{"_index" : "person","_type" : "_doc","_id" : "1","_version" : 1,"_seq_no" : 0,"_primary_term" : 3,"found" : true,"_source" : {"name" : "john","age" : 10,"born" : "2010-12-01","tags" : ["boy","sunny"]}}
match查询
GET /sit_midea_auth_role/_search{"query": {"match": {"roleCode": "RL201912040006"}}}
bool查询
·
查询结果字段说明
| 字段 | 含义 |
|---|---|
| _index | 文档索引 |
| _type | 文档类型 |
| _id | 文档id |
| _version | 文档版本,更新时自动加1,针对指定文档 |
| _seq_no | 版本控制使用,针对于当前index |
| _primary_term | |
| found | 是否查询到,true or false |
| _source | 查询结果 |
3. 更新文档
3.1 覆盖更新
PUT /person/_doc/1{"name":"lisi"}
更新后查询结果如下
{"_index" : "person","_type" : "_doc","_id" : "1","_version" : 2,"_seq_no" : 1,"_primary_term" : 3,"found" : true,"_source" : {"name" : "lisi"}}
3.2 更新指定字段
POST /person/_update/1{"doc": {"name":"lier"}}
3.3 更新指定查询文档
POST /index/_update_by_query{"script":{"source":"ctx._source.deleteFlag = 1","lang":"painless"},"query":{"bool": {"must": [{"term": {"roleCode.keyword": {"value": "RL201905080024"}}}]}}}
4. 删除文档
格式: DELETE /index/_doc/id
DELETE /person/_doc/1
根据条件删除:_delete_by_query
POST /index/_delete_by_query{"query": {"match_all": {}}}#不带条件则删除所有
