Question: How do you select only a few fields you want from Elasticsearch Query using C# in the Asp.Net Application?
[Elasticsearch source query] [elasticsearch fields query]
Login to See the Rest of the Answer
Answer: If you want to retrieve the selected field from Elasticsearch C-Sharp then you should use the "Source" option that the NEST Library and Elasticsearch provide. See the code below:
await _elasticClient.SearchAsync<MyModel>
(
s => s.Source(sf => sf
.Includes(i => i
.Fields(
f => f.MyField,
f => f.Category,
f => f.AnotherOne,
f => f.Id,
f => f.AnotherField
)
)
)
If this helped you then leave us a comment below to let others know how helpful this was.
If you have a question related to this writing, drop us a comment below and will answer your question.