[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1t8BEStV-1592913263205)(C:\Users\lvcky2333\AppData\Roaming\Typora\typora-user-images\image-20200623170216177.png)]
与传统数据库对比
常用method
- put 增加/改变
PUT /索引/类型/1
{
json串
}
- update 改变
- delete 删除
DELETE /索引
- get 查询
- GET /索引/类型/_search //查询所有
- GET /索引/类型/_search
{"query":{"match_all":{}}}
- GET /索引/类型/1?_source=字段列表
- GET /索引/类型/_search
{"query":{
"match":{json串}
}
}
- post 查询/改变
POST /索引/类型/1/_updata
{
"doc":{
列名:值 //精准的修改某一列
}
}
POST /_bulk //批量操作,增删改 必须写在同一行,不能换行
- {"create":{"index":索引,"_type":类型,"_id":编号}}
{json串}
- {"update":{"index":索引,"_type":类型,"_id":编号}}
"doc":{json串}
- {"delete":{"index":索引,"_type":类型,"_id":编号}}
- head 改变/删除
es查询
- match_all:返回所有文档
GET stu/_search
{
"query": {
"match_all": {}
}
}
- match:布尔匹配查询 有匹配字符,并包含任意一个就返回true
GET stu/_search
{
"query": {
"match": {
"name":"John Kerry"
}
}
}
- match_phrase:短语匹配查询 必须完全匹配才返回
GET stu/_search
{
"query": {
"match_phrase": {
"name":"John Kerry"
}
}
}
- match_phrase_prefix:短语前缀匹配查询,类似match_phrase,但最后一个分词作为前缀匹配
GET stu/_search
{
"query": {
"match_phrase_prefix": {
"name":"John Ke"
}
}
}
- multi_match:多字段匹配查
GET stu/_search
{
"query": {
"multi_match": {
"query": "John like cooking",
"fields": ["name","interest"]
}
}
}
- range:范围查询
GET stu/_search
{
"query": {
"range" : {
"yearOfBorn" : {
"gte" : 1995,
"lte" : 2000
}
}
}
}
- bool:布尔查询
// 查询喜欢“cooking”且不在1995-2000间出生的学生
GET stu/_search
{
"query": {
"bool": {
"must": {
"match": { "interest": "cooking"} },
"must_not": {
"range": { "yearOfBorn": { "gte": 1995, "lte": 2000 }}}
}
}
}
match": { “interest”: “cooking”} },
“must_not”: {
“range”: { “yearOfBorn”: { “gte”: 1995, “lte”: 2000 }}}
}
}
}