我有一些代码应该从搜索中返回 5 个匹配项。
如果我在浏览器中尝试查询,我会得到 5 个结果:
http://localhost:9200/_search?q=Testing
如果我使用 SENSE 编辑器,它还会显示我的 5 个结果:
Server=localhost:9200
POST _search
{
"query": {
"query_string": {
"query": "Testing"
}
}
}
但是我在控制器中的 C# 代码没有得到任何匹配。我错过了什么?
Uri localhost = new Uri("http://localhost:9200");
var setting = new ConnectionSettings(localhost);
setting.SetDefaultIndex("videos");
var client = new ElasticClient(setting);
var result = client.Search<SearchHint>(
body => body.Query(
query => query.QueryString(
qs => qs.Query(keys))));
var results = new SearchResults()
{
Results = result.Documents.ToList() <-- this has 0 items
};
编辑1:
public class SearchHint
{
public string Id { get; set; }
public string Title { get; set; }
public int NumItems { get; set; }
public bool IsList { get; set; }
public SearchHint(string id, string title, int numItems, bool isList)
{
Id = id;
Title = title;
NumItems = numItems;
IsList = isList;
}
}
编辑 2: 索引中有 4 种类型(视频\列表、视频\视频、视频\作者、视频\类别)。任何搜索都应该搜索所有类型,而不是任何特定类型。