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.
- Double Choc
- Ben & Jerries Double Choc
- Fairy Farms Double Choc
- Dan's Double Chocolate
Here is a simplified example of a C# Nest based query.
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.
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?
i.e. Searching for "Double Choc" one would expect...
- Double Choc
- Ben & Jerries Double Choc
- etc.
Searching for "Ben & Jerries Double Choc" one would expect...
- Ben & Jerries Double Choc
- Dan's Double Choc
- etc.
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.