Elasticsearch多重匹配不会增加字段,这是代码。
{
"size": 15,
"from": 0,
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "shoes",
"fields": ["category^3", "brand^2", "title^1", "description"],
"fuzziness": "AUTO"
}
},
"filter": {
"bool": {
"must": [],
"should": null
}
}
}
}
}
理想情况下,我想要的是,如果有人搜索关键字“鞋子”,那么他应该获得相关结果。在这种情况下,应查看是否有鞋类,应将其提升为3。然后应查看是否有任何品牌的关键词为“鞋”,应将其提升为2。然后它应该在标题和说明中查找。
因此,如果产品具有上述所有条件,那么它应该显示出最高的提升。
编辑:这是我的映射。
{
"mappings": {
"products": {
"properties": {
"variations": {
"type": "nested",
"index": "not_analyzed"
}
}
}
}
}
编辑:我还没有为其余字段定义类型。我想将其保留为默认值。其次,我对查询嵌套字段不感兴趣。因为这些通常包括产品的变体,例如颜色,尺寸等。这是示例文档。
{
"title": "100% Cotton Unstitched Suit For Men",
"slug": "100-cotton-unstitched-suit-for-men",
"price": 200,
"sale_price": 0,
"vendor_id": 32,
"featured": 0,
"viewed": 20,
"stock": 4,
"sku": "XXX-B",
"rating": 0,
"active": 1,
"vendor_name": "house_of_suits",
"brand": "armani",
"category": [
"men_fashion",
"traditional_clothing",
"unstitched_fabric"
],
"image": "imagename.jpg",
"variations": [
{
"variation_id": "34",
"stock": 5,
"price": 200,
"variation_image": "",
"sku": "XXX-C",
"size": "m",
"color": "red"
},
{
"variation_id": "35",
"stock": 5,
"price": 200,
"variation_image": "",
"sku": "XXX-D",
"size": "l",
"color": "red"
}
]
}
最佳答案
已过时的过滤查询已被弃用,并应由至少包含must子句和filter子句的bool代替。同样,您的场提升是正确的,但是,multi_match得分根据您定义的类型而有所不同。默认类型best_fields,使用best字段中的_score。在下面的示例中,下面的示例使用most_fields类型,该类型结合了每个字段的得分,并应完成您想要的操作。我将查看this页面以了解有关不同类型的更多信息。
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "shoes",
"fields": ["category^3", "brand^2", "title^1", "description"],
"type": "most_fields"
}
}
],
"filter": {
}
}
}
}
关于elasticsearch - Elasticsearch Boosting不适用于多重比赛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46595634/