就像氧化还原所说的那样,完成建议器确实很简单,不支持条目提升。我的解决方案是创建两个建议字段,一个用于品牌,一个用于产品名称:
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" } } }}在删除重复项之后,您可以将品牌建议的提议列表附加到产品建议之一中,以仅具有相关建议,无重复项和产品建议的形式具有建议列表。
另一个解决方案是使用查询来提升品牌和产品,而不是使用建议者。但是,此实现比较慢,因为它不使用建议程序。



