ES使用
shards 分片数
ES存储数据可以存储在多个分片
下载ES
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-darwin-x86_64.tar.gz
curl http://127.0.0.1:9200s
下载kibana
curl -L -O https://artifacts.elastic.co/downloads/kibana/kibana-7.9.3-darwin-x86_64.tar.gz
http://127.0.0.1:5601/
ES 健康情况查询
curl -X GET "localhost:9200/_cat/health?v&pretty"
索引数据管理
添加数据
POST product-info/_doc
{"name":"banana","price":15,"desc":" expensive banana"}
批量插入数据
PUT product-info/_bulk
{"create":{}}
{"name":"banana","price":10,"area":"domestic","desc":"good banana"}
{"create":{}}
{"name":"banana","price":15,"area":"foreign","desc":"expensive bannana"}
{"create":{}}
{"name":"apple","price":20,"area":"domestic","desc":"good apple"}
{"create":{}}
{"name":"black berry","price":20,"area":"foreign","desc":"black berry is acidic"}
{"create":{}}
{"name":"cherry","price":20,"area":"domestic","desc":"cherry is delicious"}
删除索引
DELETE product-info/
设置索引mapping
PUT product-info/
{
"mappings": {
"properties": {
"name":{ "type": "keyword"},
"price":{ "type": "integer"},
"desc":{ "type": "keyword"},
"area":{ "type": "keyword"}
}
}
}
数据查询
普通数据查询
GET customer/_search
{
"query" : {
"match" : { "firstname": "Jennifer" }
}
}
折叠数据查询结果
GET product-info/_search
{
"query": {
"match": {
"name": "apple"
}
},
"collapse": {
"field": "price"
}
}
多个查询条件查询
GET /product-info/_search
{
"query": {
"bool": {
"filter": [
{"term": {
"name": "banana"
}},
{
"term": {
"price": 10
}
}
]
}
}
}
聚合查询
简单聚合
GET product-info/_search
{
"aggs": {
"count_fruit": {
"sum": {
"field": "price"
}
}
}
}
桶聚合
根据产品名对产品单价求和
GET product-info/_search
{
"aggs": {
"count_fruit": {
"terms": {
"field": "name"
},
"aggs": {
"price_sum": {
"sum": {
"field": "price"
}
}
}
}
}
}
根据条件对查询结果进行聚合
GET product-info/_search
{
"aggs": {
"count_fruit": {
"terms": {
"field": "name"
},
"aggs": {
"area_count": {
"terms": {
"field": "area"
},
"aggs": {
"price_count": {
"sum": {
"field": "price"
}
}
}
}
}
}
}
}
多个索引查询
分页查询
Index 相关知识
静态参数:分片数、
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "Jim Hover"
}
'
curl -X GET "localhost:9200/customer/_doc/1?pretty"