1

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!

Omar Himada
  • 2,540
  • 1
  • 14
  • 31

1 Answers1

0

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)));
Omar Himada
  • 2,540
  • 1
  • 14
  • 31