I'm currently working on a NEST searcher for a phones database. I've had very little luck with the dynamic version of things in terms of making it so that a user can filter certain terms to search for in the frontend.
This is because NEST doesn't like replacing a field "f.something" with a variable. Due to this I've gone to static because I believe I can do that with some object instantiation.
However, now even though I'm getting valid NEST responses back they're always empty even though there's obviously a result to be had. Such as "Name" for field and "iPhone" for query. What am I missing? Thanks in advance.
P.S. The commented-out code used to have "bool" and "should" checks in but similarly I kept getting no results.
private ISearchResponse<MasterProduct> SearchThis(ElasticClient client, string query, string field, int pageSize, int recordNumber)
{
var searchLayout = new SearchRequest<MasterProduct>
{
Size = pageSize,
From = recordNumber,
Query = new MatchQuery
{
Field = field,
Query = query,
Fuzziness = Fuzziness.Auto,
PrefixLength = 2,
Lenient = true,
FuzzyRewrite = MultiTermQueryRewrite.TopTermsBlendedFreqs(10)
}
};
var searchResponse = client.Search<MasterProduct>(searchLayout);
return searchResponse;
}
/*var searchResponse = client.Search<MasterProduct>(s => s
.From(recordNumber)
.Size(pageSize)
.Query(q => q
.Match(a => a
.Field(f => f.MasterProductName)
.Query(query)
.Fuzziness(Fuzziness.Auto)
.PrefixLength(2)
.Fuzziness(Fuzziness.Auto)
.Lenient()
.FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
)
.Match(b => b
.Field(f => f.ManufacturerName)
.Query(query)
.Fuzziness(Fuzziness.Auto)
.PrefixLength(2)
.Fuzziness(Fuzziness.Auto)
.Lenient()
.FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
)
.Match(c => c
.Field(f => f.MasterAttributes)
.Query(query)
.Fuzziness(Fuzziness.Auto)
.PrefixLength(2)
.Fuzziness(Fuzziness.Auto)
.Lenient()
.FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
)
)
);
Console.WriteLine(searchResponse.Hits.Count());
foreach (var hit in searchResponse.Documents)
{
Console.WriteLine(hit.MasterProductId);
}*/
}
.Suffix(...)
: elastic.co/guide/en/elasticsearch/client/net-api/current/… – Russ CamField
type has an implicit conversion fromstring
, so you can pass thestring
input for the field. Note that strings are taken verbatim and not cased as expressions orPropertyInfo
are, so if you're rolling with the defaults, the string value will need to be camel-cased e.g.masterProductName
. – Russ Cam