[英]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. 我正在尝试使用ElasticClient.Search
方法进行搜索,但是无论我设置了什么术语或搜索依据的字段,我总是得到0个结果。
Here is the structure of my POCO: 这是我的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! 任何帮助表示赞赏!
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)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.