# 查看状态
GET /_cat/health?v
############### 查看索引
GET /_cat/indices?v
############### 增加文档
PUT /index/type/id
############### 查看文档
GET /index/type/id
############### 查询类型全部名称
GET /index/type/_search
############### 查询名字里面带有牙膏的文档,并且价格倒序
GET /ecommerce/product/_search?q=name:yagao&sort=price:desc
############### 构造request json 语句查询
############### 查询所有数据
GET /ecommerce/product/_search
{
"query": {
"match_all": {}
}
}
############### 查询名称里面包含yagao的文档,同时价格按照倒序排序
GET /ecommerce/product/_search
{
"query": {
"match": {
"name":"yagao"
}
}
,"sort": [
{"price": "desc"}
]
}
############### 从文档里面第2个开始查询,显示1个数据
GET /ecommerce/product/_search
{
"query": {"match_all": {}}
, "from": 1
, "size": 1
}
############### 指定要查询出来的商品的价格和数量
GET /ecommerce/product/_search
{
"query": {"match_all": {}}
, "_source": ["name","price"]
}
############### 过滤,查询名称里面有牙膏,且价格大于等于30
GET /ecommerce/product/_search
{
"query": {"bool": {
"must": [
{
"match": {
"name": "yagao"
}
}
]
, "filter": {
"range": {
"price": {
"gte": 30
}
}
}
}
}
}
############### 全文检索
GET /ecommerce/product/_search
{
"query": {
"match": {
"producer": "zhonghua gaolujie"
}
}
}
############### 短语检索
GET /ecommerce/product/_search
{
"query": {
"match_phrase": {
"name": "zhonghua yagao"
}
}
}
############### 高亮检索
GET /ecommerce/product/_search
{
"query": {
"match_phrase": {
"name": "zhonghua yagao"
}
}
, "highlight": {
"fields": {
"name": {}
}
}
}
############### 聚合分析
------------------------------------ · 查询tags分组
GET /ecommerce/product/_search
{
"size": 0
, "aggs": {
"agg_test": {
"terms": {"field":"tags"}
}
}
}
------------------------------------ · 名字里面包含gaolujie的分组
GET /ecommerce/product/_search
{
"size": 0
, "query": {
"match": {
"name": "gaolujie"
}
}
, "aggs": {
"agg_test": {
"terms": {
"field": "tags",
}
}
}
}
------------------------------------ · 先分组,再算每组的平均值,计算每个tag下的商品的平均价格
GET /ecommerce/product/_search
{
"size": 0,
"aggs" : {
"group_by_tags" : {
"terms" : { "field" : "tags" },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}
------------------------------------ · 计算每个tag下的商品的平均价格,并且按照平均价格降序排序
GET /ecommerce/product/_search
{
"size": 0,
"aggs" : {
"all_tags" : {
"terms" : { "field" : "tags", "order": { "avg_price": "desc" } },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}
############### 修改文档
1
PUT /ecommerce/product/1
{
"name" : "jiaqiangban gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"producer" : "gaolujie producer",
"tags": [ "meibai", "fangzhu" ]
}
2
POST /ecommerce/product/1/_update
{
"doc": {
"name": "jiaqiangban gaolujie yagao"
}
}
############### 搜索方式
############### 删除文档
DELETE /ecommerce/product/1