代码之家  ›  专栏  ›  技术社区  ›  Omar Himada

ElasticSearch.net和Nest-搜索始终返回0个结果

  •  1
  • Omar Himada  · 技术社区  · 7 年前

    我正在尝试使用 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)
    {
        ...
    }
    

    感谢您的帮助!

    1 回复  |  直到 7 年前
        1
  •  0
  •   Omar Himada    7 年前

    发现了问题。我没有设置索引!我把我的搜索代码改成了这个,它可以工作:

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