Reputation: 21826
I am indexing the following Document class for indexing:
public class DoctorDocument
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public int Experience { get; set; }
}
I am using the following code for searching the index.
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(
node,
defaultIndex: "my-application"
);
var client = new ElasticClient(settings);
var searchResults = client.Search<DoctorDocument>(s => s.From(0)
.Size(100)
.Query(q =>
q.Term(t => t.Name, "Deepak Singhal"))
);
For some reason, searchResults is returning no document, even though there is a name "Deepak Singhal" in the index. Any pointers to why nothing is being returned?
Upvotes: 0
Views: 170
Reputation: 21826
As @Manolis has pointed out in the comment, the Term descriptor does not work well with spaces. MatchQueryDescriptor on the field name worked well for me.
var searchResults = client.Search<DoctorDocument>(s => s.From(0)
.Size(100)
.Query(q =>
q.Match(mqd => mqd.OnField("name").Query("Deepak Singhal"))
));
Upvotes: 1