Hi!
I`am trying implement autocomplete feature for multiple fields with official high-level NEST client.
But quick and dirty solution looks like this:
public async Task<IEnumerable<string>> Complete(string text)
{
var sd1 = new SearchDescriptor<Assignment>().Suggest(
scd => scd.Completion(
"n1",
csd => csd
.Field(x => x.Title)
.Prefix(text)));
var sd2 = new SearchDescriptor<Assignment>().Suggest(
scd => scd.Completion(
"n2",
csd => csd
.Field(x => x.Theme)
.Prefix(text)));
var sd3 = new SearchDescriptor<Assignment>().Suggest(
scd => scd.Completion(
"n3",
csd => csd
.Field(x => x.TrainingKit)
.Prefix(text)));
var task1 = _elasticClient.SearchAsync<Assignment>(sd1);
var task2 = _elasticClient.SearchAsync<Assignment>(sd2);
var task3 = _elasticClient.SearchAsync<Assignment>(sd3);
await Task.WhenAll(task1, task2, task3);
var resp1 = task1.Result.Suggest.SelectMany(x => x.Value).SelectMany(x => x.Options).Select(x => x.Text).Distinct();
var resp2 = task2.Result.Suggest.SelectMany(x => x.Value).SelectMany(x => x.Options).Select(x => x.Text).Distinct();
var resp3 = task3.Result.Suggest.SelectMany(x => x.Value).SelectMany(x => x.Options).Select(x => x.Text).Distinct();
return resp1.Concat(resp2).Concat(resp3);
}
Completion
dsl method have only Field
option, but not Fields
. Can i implement this fearure without call Task.WhenAll(...)
with NEST?