mapping
delete
### delete DELETE {{host}}/goods content-type: application/json accept: application/json
query
### mapping GET {{host}}/goods content-type: application/json accept: application/json
create
### create PUT {{host}}/goods content-type: application/json accept: application/json { "mappings": { "properties": { "goodsId": { "type": "long" }, "goodsName": { "type": "text" }, "goodsNameSort": { "type": "keyword" }, "supTypeId": { "type": "keyword" }, "typeId": { "type": "keyword" }, "products": { "type": "nested", "properties": { "productSapId": { "type": "keyword" }, "name": { "type": "text" }, "priceSort": { "type": "integer" }, "priceRdSapIds": { "type": "keyword" }, "tagsSort": { "type": "integer" }, "tags": { "type": "nested", "properties": { "tagId": { "type": "long" }, "sort": { "type": "integer" }, "startTime": { "type": "date", "format": "yyyy-MM-dd" }, "endTime": { "type": "date", "format": "yyyy-MM-dd" } } }, "promotions": { "type": "nested", "properties": { "promotionId": { "type": "long" }, "rdSapIds": { "type": "keyword" }, "promotionType": { "type": "keyword" }, "startTime": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "endTime": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } }, "stocks": { "type": "nested", "properties": { "stockId": { "type": "keyword" }, "stock": { "type": "integer" }, "stockWeek": { "type": "integer" }, "stock14Days": { "type": "integer" }, "stockMonth": { "type": "integer" } } }, "isHot": { "type": "keyword" } } } } } }
search
### filter
POST {{host}}/goods/_search
content-type: application/json
accept: application/json
{
"explain": true,
"query": {
"bool": {
"must": [
{
"terms": {
"supTypeId": [
1
]
}
},
{
"terms": {
"typeId": [
2
]
}
},
{
"nested": {
"path": "products",
"query": {
"bool": {
"must": [
{
"nested": {
"path": "products.tags",
"query": {
"terms": {
"products.tags.tagId": [
4001
]
}
}
}
},
{
"terms": {
"products.priceRdSapIds": [
3001
]
}
},
{
"nested": {
"path": "products.stocks",
"query": {
"script": {
"script": "for (int i=0;i<doc['products.stocks.stock'].length;i++){if(doc['products.stocks.stock'][i]>0)return true;}return false;"
}
}
}
}
]
}
}
}
}
]
}
},
"sort": [
{
"products.tagsSort": {
"order": "desc",
"mode": "sum",
"nested": {
"path": "products"
}
}
}
]
}
test data
### 1001:全部
POST {{host}}/goods/_doc/1001
content-type: application/json
accept: application/json
{
"goodsId": 1001,
"goodsName": "1001",
"goodsNameSort": "1001",
"supTypeId": [
1
],
"typeId": [
2
],
"products": [
{
"productSapId": 2001,
"name": "2001",
"priceRdSapIds": [
3001
],
"tagsSort": 1,
"tags": [
{
"tagId": 4001,
"sort": 1
}
],
"stocks": [
{
"stockId": 1,
"stock": 0,
"stockWeek": 0,
"stock14Days": 0,
"stockMonth": 0
},
{
"stockId": 10,
"stock": 1,
"stockWeek": 0,
"stock14Days": 0,
"stockMonth": 0
}
]
},
{
"productSapId": 2002,
"name": "2002",
"tagsSort": 2,
"tags": [
{
"tagId": 3,
"sort": 2
}
],
"stocks": [
{
"stockId": 2,
"stock": 1,
"stockWeek": 0,
"stock14Days": 0,
"stockMonth": 0
}
]
}
]
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。