I am trying to write a query that returns only one of the fields to me. Right now I am storing the filePath of the file and the contents of the file, and in my search I want to search the contents, but only return filePath.
I start with this statement:
var searchResults = client.Search<File>( s => s.Query(q => q.Wildcard(w => w.Value("*" + genre + "*").OnField("fileContents"))).AllIndices().AllTypes());
which returns the results in searchResults.Documents and adds fields to it.
var searchResults = client.Search<File>( s => s.Query(q => q.Wildcard(w => w.Value("*" + genre + "*").OnField("fileContents"))).AllIndices().AllTypes().Fields(f=>f.filePath));
And it has nothing in searchResults.Documents , but shows the correct number of hits with searchResults.Hits.Total .
File Class:
public class File { public string filePath { get; set; } public string fileContents { get; set; } }
This generates the following json request:
{ "fields": [ "filePath" ], "query": { "wildcard": { "fileContents": { "value": "*int*" } } } }
That when run in Sense returns the results, and when doing searchResults.Hits.Total - the number of hits.
However, there are no entries in searchResults.Document IEnumerable.
Is there any other way that I have to return one specific field?
c # elasticsearch nest
Nived
source share