#创建索引映射(类似于关系型数据库中的表结构)
PUT /my_store
{"mappings":{"properties":{"price":{"type":"float"},
"productName":{"type":"text",
"analyzer":"ik_smart",
"search_analyzer":"ik_max_word"},
"size":{"type":"text"},
"tag":{"type":"keyword"}}}}#直接新增customer
PUT /customer/_doc/1
{"name":"cxy@toc"}#查看所有索引
GET _cat/indices
#单条新增,指定id (会删除没有的字段,无变化重复执行:版本会递增)
PUT /my_store/_doc/1
{"productName":"李宁休闲裤",
"size":"L",
"price":100.5
}#修改(不会修改没有的字段,无变化重复执行:版本号不变)
POST /my_store/_update/1
{"doc":{"productName":"李宁休闲裤G",
"size":"L",
"price":100.5
}}#查看这条数据 (注意两种方式_version区别)
GET /my_store/_doc/1
#批量插入
POST /my_store/_doc/_bulk
{"index":{}}{"productName":"2017秋装新款文艺衬衫女装","size":"L","price":100.5}{"index":{}}{"productName":"2017秋装新款文艺衬衫女装","size":"M","price":110.5}{"index":{}}{"productName":"2017秋装新款文艺衬衫女装","size":"S","price":120.5}{"index":{}}{"productName":"2018春装新款牛仔裤女装","size":"M","price":130.5}{"index":{}}{"productName":"2018春装新款牛仔裤女装","size":"S","price":140.5}{"index":{}}{"productName":"2017春装新款休闲裤女装","size":"L","price":150.5}{"index":{}}{"productName":"2017春装新款休闲裤女装","size":"S","price":160.5}
POST /my_store/_doc/_bulk
{"index":{}}{"productName":"2017春装女裤","size":"L","price":100.5}{"index":{}}{"productName":"2017夏装女裤","size":"M","price":110.5}{"index":{}}{"productName":"2018秋装女鞋","size":"S","price":120.5}{"index":{}}{"productName":"2018冬装女鞋装","size":"M","price":130.5}{"index":{}}{"productName":"2019春装男裤","size":"S","price":140.5}{"index":{}}{"productName":"2019夏装男裤","size":"L","price":150.5}{"index":{}}{"productName":"2019秋装男鞋","size":"S","price":160.5}{"index":{}}{"productName":"2019冬装男鞋","size":"S","price":160.5}#获得总记录数
GET /my_store/_count
#查看索引所有数据
GET /my_store/_search
#查看索引所有数据,排序,分页
GET /my_store/_search
{"query":{"match_all":{}},
"sort":[{"price":"asc"}],
"from":0,
"size":5}#条件检索
GET /my_store/_search
{"query":{"match":{"size":"S"}}}#聚合
GET /my_store/_search
{"query":{"match":{"productName":"春装"}},
"size":0,
"aggs":{"sizes":{"terms":{"field":"price"}}}}#删除所有
POST /my_store/_delete_by_query
{"query":{"match_all":{}}}