简单入门
GET _search
{
"query": {
"match_all": {}
}
}#查询所有索引
GET _cat/indices?v#删除索引
DELETE person2#创建索引
PUT obj#查看索引
GET obj#创建文档
POST obj/_doc
{
"name":"张三",
"age":13,
"avatar":"http://houniao-images.oss-cn-shenzhen.aliyuncs.com/wyc/Template/upload/6639f262e520b.jpg",
"province":"henan"
}#创建文档 指定id创建
POST obj/_doc/1
{
"name":"李四",
"age":18,
"avatar":"http://houniao-images.oss-cn-shenzhen.aliyuncs.com/wyc/Template/upload/6639f262e520b.jpg",
"province":"四川"
}#指定id查询文档信息
GET obj/_doc/1#全量查询
GET obj/_search#全量修改 改动整个数据结构
PUT obj/_doc/1
{
"name":"李四1",
"age":18,
"avatar":"http://houniao-images.oss-cn-shenzhen.aliyuncs.com/wyc/Template/upload/6639f262e520b.jpg",
"province":"四川"
}#局部修改
POST obj/_update/1
{
"doc": {
"name":"李四",
"age":28
}
}#删除文档
DELETE obj/_doc/1#创建文档 指定id创建
POST obj/_doc/1
{
"name":"张三",
"age":11,
"flag":false,
"province":"四川"
}
POST obj/_doc/2
{
"name":"李四",
"age":18,
"flag":false,
"province":"广东"
}
POST obj/_doc/3
{
"name":"王五",
"age":18,
"flag":false,
"province":"北京"
}POST obj/_doc/4
{
"name":"孙六",
"age":30,
"flag":false,
"province":"四川"
}#条件查询【请求路径传递参数】
GET obj/_search?q=province:四川#条件查询【请求体传递参数数】
GET obj/_search
{
"query": {
"match": {
"province": "四川"
}
}
}#查询全部
GET obj/_search
{
"query": {
"match_all": {}
}
}#分页查询【from计算公式(页码- 1)* size】
GET obj/_search
{
"query": {
"match_all": {}
},
"from": 0,
"size": 2
}#指定数据段 相同于mysql的field
GET obj/_search
{
"query":{
"match_all":{
}
},
"from":0,
"size":2,
"_source":["name"]
}#排序
GET obj/_search
{
"query":{
"match_all":{}
},
"from":0,
"size":3,
"_source":["age","name"],
"sort" : {
"age" : {
"order" : "desc"
}
}
}#单个条件查询
GET obj/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"province": "四"
}
}
]
}
}
}#多条件查询
GET obj/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"province": "四川"
}
},{
"match": {
"age": 11
}
}
]
}
}
}#满足某一个条件【match 对于string类型可以模糊查询?】
GET obj/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"province": "四川"
}
},{
"match": {
"name": "四"
}
}
]
}
}
}#范围查找【range gt大于 lt小于 gte、lte大于等于、小于等于】
GET obj/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"flag": false
}
}
],
"filter": [
{
"range": {
"age": {
"gte": 1,
"lte": 20
}
}
}
]
}
}
}#高亮显示
GET obj/_search
{
"query": {
"match": {
"name": "四"
}
},
"highlight": {
"fields": {
"name": {}
}
}
}#聚合查询
GET obj/_search
{
"aggs": {
"group_one" :{
"terms": {
"field": "province.keyword",
"size": 10
}
},
"group_two" :{
"terms": {
"field": "age",
"size": 1
}
}
},
"size": 0
}#聚合查询 求平均值
GET obj/_search
{
"aggs": {
"age_avg": {
"avg": {
"field": "age"
}
}
},
"size":0
}