I'm pretty new to Elastic Search and the Elastic Search API I'm using in C#: PlainElastic.Net.
I have a simple request, but I'm stuck with it: how can I add multiple (not hardcoded) facets in my querybuiler?
//code has been simplified
//list of fields I want to be added in my facet part of the querybuilder
List<string> FacetFields = new List<string>{"field1", "field2", "fieldN"};
//qb is already instantiated with a simple ES query
//I want now to add facets definition
qb.Facets(_facets =>
FacetFields.ForEach(_ff =>
_facets.Terms(t => t
.FacetName("FacetsFor" + _ff)
.Field(_ff)
);
});
);
This does not compile, the error is:
Can not convert lambda expression to delegate type '
System.Func<PlainElastic.Net.Queries.Facets<MyType>,PlainElastic.Net.Queries.Facets<MyType>>
', as some return types of block are not implicitly convertible to the return type delegate