Omar Himada
Omar Himada

Reputation: 2588

Elasticsearch.NET & NEST - search always returning 0 results

I'm trying to search using the ElasticClient.Search method but no matter what terms I set, or field I search by, I always get 0 results.

Here is the structure of my POCO:

public class MyParent
{
    public MyChild MyChild { get; set; }
}

public class MyChild
{
    public string MyField { get; set; }
}

And then here is my actual search code:

string searchTerm = "myChild.myField";
string searchValue = "C";

Field searchField = new Field(searchTerm);

ISearchResponse<MyParent> result =
    Client.Search<MyParent>(s =>
        s.Query(q => q.Term(searchField, searchValue)));

if (result != null && 
    result.Documents != null && 
    result.Documents.Count != 0)
{
    ...
}

Any help appreciated!

Upvotes: 1

Views: 1207

Answers (1)

Omar Himada
Omar Himada

Reputation: 2588

Found the problem. I wasn't setting the index! I changed my search code to this and it works:

ISearchResponse<MyParent> result =
    Client.Search<MyParent>(s =>
        s.Index("my_index_").Query(q => q.Term(searchField, searchValue)));

Upvotes: 0

Related Questions