我正在通过 ElasticSearch NEST C# 客户端运行一个简单的查询。当我通过 http 运行相同的查询时,我收到结果,但我从客户端返回的文档为零。
这就是我填充数据集的方式:
curl -X POST "http://localhost:9200/blog/posts" -d @blog.json
此 POST 请求返回 JSON 结果:
http://localhost:9200/_search?q=adipiscing
这是我没有返回任何内容的代码。
public class Connector
{
private readonly ConnectionSettings _settings;
private readonly ElasticClient _client;
public Connector()
{
_settings = new ConnectionSettings("localhost", 9200);
_settings.SetDefaultIndex("blog");
_client = new ElasticClient(_settings);
}
public IEnumerable<BlogEntry> Search(string q)
{
var result =
_client.Search<BlogEntry>(s => s.QueryString(q));
return result.Documents.ToList();
}
}
我缺少什么?提前致谢 ..
NEST 尝试猜测类型和索引名称,在您的情况下它将使用 /blog/blogentries
blog
因为你告诉默认索引是和blogentries
因为它会将您传递给的类型名称小写并复数化Search<T>
.
您可以控制哪种类型和索引,如下所示:
.Search<BlogEntry>(s=>s.AllIndices().Query(...));
这将使 NEST 知道您实际上想要搜索所有索引,因此 Nest 会将其转换为/_search
在根上,等于您在curl上发出的命令。
您最可能想要的是:
.Search<BlogEntry>(s=>s.Type("posts").Query(...));
这样 NEST 就会搜索/blog/posts/_search
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)