"_index" : "db_test", -- index数据库 辅助理解
"_type" : "user", -- type 表 辅助理解
"_id" : "1", -- id 唯一主键 辅助理解
-- 查询有哪些索引
GET _cat/indices
命令练习
1、创建库
PUT /db_test
{
"settings": {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
2、修改
PUT /db_test/_settings
{
"number_of_replicas": 1
}
3、为user表增加一条数据
put /db_test/user/1
{
"name":"张三",
"age":11
}
4、查询全部
POST /db_test/user/_search
{
"query":{
"match_all":{}
}
}
5、通过名字查询
POST /db_test/user/_search
{
"query":{
"match":{
"name":"张三"
}
}
}
6、修改数据
put /db_test/user/1
{
"name":"李四",
"age":13
}
7、删除索引
DELETE /db_test
8、聚合查询 -- 按statDimensionWeekTime分组count聚合 weekTime 别名
POST /overall_store_day_v4/_search
{
"size":0,
"aggs":{
"weekTime":{
"terms":{
"field":"statDimensionWeekTime"
}
}
}
}
9、聚合复杂查询 根据statDimensionWeekTime分组,求 indoorCount 平均值、最大、最小值、求和值
POST /overall_store_day_v4/_search
{
"size": 0,
"aggs": {
"weekTime": {
"terms": {
"field": "statDimensionWeekTime"
},
"aggs": {
"indoorCount_avg": {
"avg": {
"field": "indoorCount"
}
},
"indoorCount_min": {
"min": {
"field": "indoorCount"
}
},
"indoorCount_max": {
"max": {
"field": "indoorCount"
}
},
"indoorCount_sum": {
"sum": {
"field": "indoorCount"
}
}
}
}
}
}