需求A:
搜索范围:商品名称、产品类目(四级、三级、二级、一级分类,分类从小到大筛选)
步骤1: 创建mapping
{
"caicongyang-product": {
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"brandname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"cancelflag": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"createdate": {
"type": "date"
},
"createuser": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"isimport": {
"type": "long"
},
"modify_date": {
"type": "date"
},
"modifyuser": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"product_id": {
"type": "long"
},
"productalias": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productcatename0": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"productcatename1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"productcatename2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"productcatename3": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"productcity": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productionplacetext": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"productname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
},
"state": {
"type": "long"
},
"suppliername": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ik_smart"
}
}
}
}
}
2. 搜索dsl
{
"query":{
"bool":{
"must":[
{
"match":{
"isimport":0
}
},
{
"match":{
"state":5
}
},
{
"match":{
"cancelflag":"0"
}
},
{
"bool":{
"should":[
{
"match":{
"productname":"牛肉"
}
},
{
"match":{
"productcatename0":{
"query":"牛肉",
"boost":10
}
}
},
{
"match":{
"productcatename1":{
"query":"牛肉",
"boost":8
}
}
},
{
"match":{
"productcatename2":{
"query":"牛肉",
"boost":6
}
}
},
{
"match":{
"productcatename3":{
"query":"牛肉",
"boost":6
}
}
}
]
}
}
]
}
},
"sort":[
{
"_score":{
"order":"desc"
}
}
],
"from":0,
"size":10
}
优化思考:
a. keyword 优化(试用上面搜索结果的二次搜索,精确匹配)
{
"match": {
"suppliername.keyword": "福州东展国际贸易有限公司"
}
}
b..constant_score 优化 (减少score计算过程 )
{
"constant_score": {
"filter": {"term": {
"state": 5
}}
}
}
query bool 权重分析
bool 下级包含must, must_not,filter ,should
同⼀一层级下的竞争字段,具有有相同的权重
通过嵌套 bool 查询,可以改变对算分的影响;
后续:
es安装可以查看我的上篇文章:https://blog.csdn.net/caicongyang/article/details/107180168
如果我的文章对你有帮助,可以请我喝瓶水!