[英]Boosting elasticsearch results with NEST when a secondary field is a specific value
I have a large index of Ice Cream objects. 我的冰淇淋对象索引很大。
public class IceCream
{
public string Description {get; set;}
public bool IsGeneric { get; set; }
public double Price { get; set; }
}
I have a large database of products that are used to make ice cream milkshakes. 我有一个用于制作冰淇淋奶昔的大型产品数据库。 The business mostly uses a generic white label product but can at times be forced to use a branded product due to supply chain issues. 该企业主要使用通用白标产品,但由于供应链问题,有时可能会被迫使用品牌产品。 Please see the example data below for reference. 请参阅下面的示例数据以供参考。
Here is a simplified example of a C# Nest based query. 这是基于C#Nest的查询的简化示例。
var searchInputText = "Ben & Jerries double choc";
var query = new MatchQuery()
{
IsVerbatim = false,
Field = "description",
Query = searchInputText
};
var search = new SearchRequest()
{
Query = query,
From = 0,
Size = 30
};
var results = client.Search<IceCream>(search);
The query works perfectly when searching for branded products. 在搜索品牌产品时,该查询可以完美地工作。 However, searching for "Double Choc" returns Ben & Jerries Double Choc with a higher relevance than the generic "Double Choc" product. 但是,搜索“ Double Choc”将返回Ben&Jerries Double Choc,其相关性要比通用“ Double Choc”产品高。
Is there a way via Nest to utilise "should" to boost the IsGeneric = true field to ensure that when no brand is included in the search the generic listing has the highest relevance? 是否可以通过Nest使用“应”来增强IsGeneric = true字段,以确保当搜索中未包含任何品牌时,通用列表具有最高的相关性?
ie Searching for "Double Choc" one would expect... 即搜索“ Double Choc”的人会期望...
Searching for "Ben & Jerries Double Choc" one would expect... 搜索“ Ben&Jerries Double Choc”的人会期望...
Note: This is a heavily simplified example. 注意:这是一个大大简化的示例。 The real world application contains 100,000 manufacturing component variances so the relevance issue is far more dramatic than it appears here. 现实世界中的应用程序包含100,000个制造要素差异,因此相关性问题远比此处出现的问题严重。
Yes, you can use a Boosting query. 是的,您可以使用Boosting查询。
client.Search<IceCream>(s =>
s.Query(q =>
q.Boosting(b =>
b.Negative(n => n.Term("isGeneric", false))
.Positive(p => p.Match(m => m.Field("description").Query(searchInputText)))
.NegativeBoost(0.2))));
By Boosting IsGeneric = false
with a Negative Boost of 0.2, you can demote all results without IsGeneric = true
by a constant value. 通过以0.2的负Boost增强IsGeneric = false
,您可以将一个没有IsGeneric = true
的结果IsGeneric = true
常数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.