第二十八节 Kibana查询ElasticSearch的操作命令简介

亮子 2024-10-25 00:37:55 266 0 0 0

1、查看索引列表

GET /_cat/indices

2、创建索引

1)创建索引

PUT /books

2)创建索引并创建静态映射


``` ## 3、查看索引

GET /books


## 4、删除索引

DELETE /books


## 5、向索引存储文档 ### 1)存储单个文档

POST /books/_doc/1
{
“bookName”: “MySQL从入门到跑路”,
“author”: “李白”,
“price” : 299.00
}

POST /books/_doc/2
{
“bookName”: “JAVA从入门到跑路”,
“author”: “杜甫”,
“price” : 199.00
}


### 3)存储多个文档

POST /my_index/_bulk
{“index”:{"_id“:”1“}}
{”userId“:1,”userName“:”王东辉“,”age“:16}
{”index“:{”_id“:”2“}}
{”userId“:2,”userName“:”白杨“,”age“:17}
{”index“:{”_id“:”3“}}
{”userId“:3,”userName“:”李丰硕“,”age":17}


## 6、查看索引中所有的文档

GET /books/_search

GET /books/_search
{
“query”: {
“match_all”: {}
}
}


## 7、根据ID查询文档

GET /books/_doc/2


## 8、查看索引信息

GET /books


## 9、全量修改

POST /books/_doc/2
{
“bookName”: “JAVA从入门到跑路V2/0”,
“author”: “李白,杜甫”,
“price” : 109.00
}

POST /books/_doc/2
{
“bookName”: “JAVA从入门到跑路V3.0”
}



## 10、删除文档 ### 1)根据ID删除文档

DELETE /books/_doc/2


### 2)批量删除文档

POST /my_index/_bulk
{“delete”:{"_id“:”1“}}
{”delete“:{”_id“:”2“}}
{”delete“:{”_id“:”3"}}


## 11、条件查询

GET /books/_search
{
“query”: {
“match”: {
“author”: “李白”
}
}
}

GET /books/_search
{
“query”: {
“match”: {
“bookName”: “从跑路”
}
}
}

GET /books/_search
{
“query”: {
“term”: {
“bookName”: “路”
}
}
}


## 12、返回特定的字段

GET /books/_search
{
“query”: {
“term”: {
“bookName”: “路”
}
}
, "_source": [“bookName”]
}


## 13、分页查询

GET /books/_search
{
“query”: {
“match_all”: {}
}
, "_source“: [“bookName”],
”from“ : 1,
”size" : 1
}


## 14、排序查询

GET /books/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“price”: {
“order”: “desc”
}
}
]
}


## 15、多条件查询

GET /books/_search
{
“query”: {
“bool”: {
“should”: [
{
“match”: {
“bookName”: “java”
}
},
{
“match”: {
“price”: “299”
}
}
]
}
}
}


## 16、区间查询

GET /books/_search
{
“query”: {
“bool”: {
“must”: [
{
“match_all”: {}
}
],
“filter”: [
{
“range”: {
“price”: {
“gte”: 10,
“lte”: 300
}
}
}
]
}

}
}


## 17、全文检索

GET /books/_search
{
“query”: {
“match”: {
“bookName”: “java跑路”
}
}
}


## 18、完全匹配

GET /books/_search
{
“query”: {
“match_phrase”: {
“bookName”: “java跑路”
}
}
}


## 19、高亮查询

GET /books/_search
{
“query”: {
“match”: {
“bookName”: “java跑路”
}
},
“highlight”: {
“pre_tags”: [“”],
“post_tags”: [“”],
“fields”: {
“bookName”: {}
}
}
}

## 20、聚合查询

GET /books/_search
{
“query”: {
“match_all”: {}
},
“size”: 0,
“aggs”: {
“price_group”: {
“terms”: {
“field”:“price”
}
}
}
}


# 21、批量添加文档

POST /my_index/_bulk
{“index”:{"_id“:”1“}}
{”userId“:1,”userName“:”李白“,”age“:16}
{”index“:{”_id“:”2“}}
{”userId“:2,”userName“:”杜甫“,”age“:17}
{”index“:{”_id“:”3“}}
{”userId“:3,”userName“:”王维“,”age":17}

GET /my_index/_search


## 22、批量删除文档

POST /my_index/_bulk
{“delete”:{"_id“:”1“}}
{”delete“:{”_id“:”2“}}
{”delete“:{”_id“:”3"}}
```