我正在尝试使用ElasticClient.Search
方法进行搜索,但是无论我设置了什么术语或搜索的字段,我总是得到0个结果。
这是我的POCO的结构:
public class MyParent
{
public MyChild MyChild { get; set; }
}
public class MyChild
{
public string MyField { get; set; }
}
然后是我的实际搜索代码:
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)
{
...
}
任何帮助表示赞赏!
最佳答案
找到了问题。我没有设置索引!我将搜索代码更改为此,并且它可以正常工作:
ISearchResponse<MyParent> result =
Client.Search<MyParent>(s =>
s.Index("my_index_").Query(q => q.Term(searchField, searchValue)));
关于c# - Elasticsearch.NET和NEST-搜索总是返回0个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50569158/