ElasticSearch 基础学习篇-API(二)

PUT 新增

PUT /book/_doc/1
{
"name":"西游记",
"book_no": "NC_128389123",
"description":"中国古典小说四大名剧之一",
"author": "吴承恩",
"price": 58.80,
"timestamp": "2021-07-06 16:57:58",
"tags": ["book", "novel"]
}

强制新增不会覆盖原有的文档信息:
PUT /book/_doc/6/_create

POST 修改

PUT /book/_doc/1/_update
POST /book/_doc/1/_update
{
"doc": {
"name":"java 高级编程珠玑",
"tags": ["java", "编程"]
}
}

delete 删除

DELETE /book/_doc/2

注意:ES不会立即删除,而是先标识删除状态,等达到一定阈值后批量删除

查询

查询文档所有字段
1、GET /book/_doc/3

查询文档部分字段
2、GET /book/_doc/3?_source_includes=name,price,book_no

3、表达式查询
GET /megacorp/employee/_search
{
"query" : {
"match" : {
"last_name" : "Smith"
}
}
}

4、复杂查询
curl -X GET "localhost:9200/megacorp/employee/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query" : {
"bool": {
"must": {
"match" : {
"last_name" : "smith"
}
},
"filter": {
"range" : {
"age" : { "gt" : 30 }
}
}
}
}
}

posted @ 2021-07-06 17:59  北方有鱼  阅读(37)  评论(0编辑  收藏  举报