栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

带有不同权重的多字段上的Elasticsearch完成建议

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

带有不同权重的多字段上的Elasticsearch完成建议

就像氧化还原所说的那样,完成建议器确实很简单,不支持条目提升。我的解决方案是创建两个建议字段,一个用于品牌,一个用于产品名称:

POST /product_index{  "mappings": {    "products": {      "properties": {        "brand": {          "type": "string",          "analyzer": "english"        },        "product_name": {          "type": "string",          "analyzer": "english"        },        "id": {          "type": "long"        },        "lookup_count": {          "type": "long"        },        "product-suggest": {          "type": "completion",          "analyzer": "simple",          "payloads": true,          "preserve_separators": true,          "preserve_position_increments": true,          "max_input_length": 50        },        "brand-suggest": {          "type": "completion",          "analyzer": "simple",          "payloads": true,          "preserve_separators": true,          "preserve_position_increments": true,          "max_input_length": 50        },        "upc": {          "type": "string"        }      }    }  }}

编制索引时,请填写两个字段:

POST /product_index/products/2{  "id": 2,  "brand": "Coca-Cola",  "product_name": "Classic Coke",  "brand-suggest": {    "input": [      "Coca-Cola"    ],    "output": "Classic Coke - Coca-Cola",    "payload": {      "id": 2,      "product_name": "Classic Coke",      "brand": "Coca-Cola",      "popularity": 10    }  },  "product-suggest": {    "input": [      "Classic Coke"    ],    "output": "Classic Coke - Coca-Cola",    "payload": {      "id": 2,      "product_name": "Classic Coke",      "brand": "Coca-Cola",      "popularity": 10    }  }}

查询时,同时对品牌和产品建议者提出建议:

POST /product_index/_search{    "suggest": {      "product_suggestion": {        "text": "coca-co",        "completion": {          "field": "product-suggest"        }      },      "brand_suggestion": {        "text": "coca-co",        "completion": {          "field": "brand-suggest"        }      }    }}

在删除重复项之后,您可以将品牌建议的提议列表附加到产品建议之一中,以仅具有相关建议,无重复项和产品建议的形式具有建议列表。

另一个解决方案是使用查询来提升品牌和产品,而不是使用建议者。但是,此实现比较慢,因为它不使用建议程序。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387423.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号