How to Select only fields you care about from Elasticsearch using NEST Library

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]

Please 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
                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.

Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

© 2022 - ErnesTech - Privacy