- 模糊匹配
- 过滤(按照属性、分类、品牌、价格区间、库存)
- 排序
- 分页
- 高亮
- 聚合分析
一. 搜索关键字
检索字段:商品sku标题
“skuTitle” : “华为 HUAWEI Mate 30 Pro 亮黑色 8GB+256GB麒麟990旗舰芯片OLED环幕屏双4000万徕卡电影四摄4G全网通手机”
bool复合查询,must必须,全文检索字段用 match,其他非 text 字段匹配用 term
GET product/_search
{"query": {"bool": {"must": [{"match": {"skuTitle": "华为"}}]}}
}
二. 检索分类
检索字段:分类id
“catalogId” : 225
match会计算热度评分,filter不计算分数效率更快,所有把不需要热度评分的字段放大filter
全文检索字段用 match,其他非 text 字段匹配用 term
GET product/_search
{"query": {"bool": {"must": [{"match": {"skuTitle": "华为"}}],"filter": {"term": {"catalogId": "225"}}}}
}
三. 检索品牌
品牌是可以多选的,检索条件为品牌id的集合
terms等价于mysql 的 in()
检索字段:品牌Id
“brandId” : 9
GET product/_search
{"query": {"bool": {"must": [{"match": {"skuTitle": "华为"}}],"filter": [{"term": {"catalogId": "225"}},{"terms": {"brandId": ["1","2","9"]}}]}}
}
四. 检索属性
: attrId----------attrValue
属性可多选
查询attrs属性下嵌入的属性attr_id需要使用nested 嵌套查询
"attrs" : [{"attrId" : 15,"attrName" : "CPU品牌","attrValue" : "高通(Qualcomm)"},{"attrId" : 16,"attrName" : "CPU型号","attrValue" : "骁龙855"}]
检索字段:属性id、属性值
“attrId” : 15,
“attrValue” : “高通(Qualcomm)”
GET product/_search
{"query": {"bool": {"must": [{"match": {"skuTitle": "华为"}}],"filter": [{"term": {"catalogId": "225"}},{"terms": {"brandId": ["1","2","9"]}},{"nested": {"path": "attrs","query": {"bool": {"must": [{"term": {"attrs.attrId": {"value": "15"}}},{"terms": {"attrs.attrValue": ["高通(Qualcomm)","以官网信息为准"]}}]}}}}]}}
}
五. 检索库存、排序、价格区间、分页
查询是否有库存
排序
查询价格区间
分页
from从第几页开始,size查询几天记录
六.product映射
PUT product
{"mappings": {"properties": {"skuId": {"type": "long"},"spuId": {"type": "keyword"},"skuTitle": {"type": "text","analyzer": "ik_smart"},"skuPrice": {"type": "keyword"},"skuImg": {"type": "keyword","index": false,"doc_values": false},"saleCount": {"type": "long"},"hasStock": {"type": "boolean"},"hotScore": {"type": "long"},"brandId": {"type": "long"},"catalogId": {"type": "long"},"brandName": {"type": "keyword","index": false,"doc_values": false},"brandImg": {"type": "keyword","index": false,"doc_values": false},"catalogName": {"type": "keyword","index": false,"doc_values": false},"attrs": {"type": "nested","properties": {"attrId": {"type": "long"},"attrName": {"type": "keyword","index": false,"doc_values": false},"attrValue": {"type": "keyword"}}}}}
}