c# - Elasticsearch.NET和NEST-搜索总是返回0个结果

标签 c# elasticsearch nest elasticsearch-net

我正在尝试使用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/

相关文章:

c# - 使用字符串字段名称动态构建具有层次结构的 linq 查询?

c# - XBAP 应用程序,这些可以在 Google Chrome 中运行吗?

c# - `Assembly.Load` 在单独的文件夹中

c# - Elasticsearch C#datetime获取日期时间默认值

.net - 使用 Nest 客户端在 Elastic Search 中等效的 SQL IN 运算符

c# - 代码如何通过 response.redirect?

solr - 太阳黑子和轮胎 gem 的区别

elasticsearch - 您好,我将整个文档数据存储到文档中,然后搜索文档数据以匹配 bool 搜索,即Java和angular和(html或css)

elasticsearch - 查找最近的时间戳

d3.js - 填补 D3 数组嵌套中的空白