ElasticSearch NEST客户端不返回结果 [英] ElasticSearch NEST client not returning results

查看:244
本文介绍了ElasticSearch NEST客户端不返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过ElasticSearch NEST C#客户端的简单查询。我收到成效,当我运行通过HTTP相同的查询,但我从客户端返回零文件



这是我如何填充数据集:

-d @ blog.json


卷曲-X POST://本地主机9200 /博客/帖子HTTP >

这POST请求返回一个JSON结果:



的http://本地主机:9200 / _search q = adipiscing



这是我有一个不返回任何东西的代码。

 公共类连接器
{
私人只读ConnectionSettings _settings;
私人只读ElasticClient _client;

公连接器()
{
_settings =新ConnectionSettings(本地主机,9200);
_settings.SetDefaultIndex(博客);
_client =新ElasticClient(_settings);
}

公开的IEnumerable< BlogEntry>搜索(串Q)
{
变种结果=
_client.Search&所述; BlogEntry&将(S => s.QueryString(Q));

返回result.Documents.ToList();
}
}



我在想什么?在此先感谢..


解决方案

NEST尝试猜测类型和索引名称,并在你的情况下,它会使用/博客/ blogentries



博客,因为那是你说的缺省索引和 blogentries ,因为这将小写和复数形式传递给搜索和LT类型名称; T>



您可以控制​​哪些类型和索引像这样:

 。搜索< BlogEntry>(S =方式> s.AllIndices()查询(...)); 

这将让NEST知道你真正想要搜索的所有指标,因此巢将它传送到 / _搜索根,等于命令你卷曲发出。



您最有可能想要的是:



  .Search< BlogEntry> (S =方式> s.Type(上岗),查询(...)); 



这样NEST搜索在 /博客/职位/ _search


I am running a simple query through the ElasticSearch NEST C# client. I receive results when I run the same query through http, but I get zero documents returned from the client.

This is how I populated the data set:

curl -X POST "http://localhost:9200/blog/posts" -d @blog.json

This POST request returns a JSON result:

http://localhost:9200/_search?q=adipiscing

This is the code I have that is not returning anything.

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();
    }
}

What am I missing? Thanks in advance ..

解决方案

NEST tries to guess the type and index name and in your case it will use /blog/blogentries

blog because that what you told the default index is and blogentries because it will lowercase and pluralize the type name you pass to Search<T>.

You can control which type and index like so:

 .Search<BlogEntry>(s=>s.AllIndices().Query(...));

This will let NEST know you actually want to search on all indices and so nest will translate it to /_search on the root, equal to the command you issued on curl.

What you most likely want is:

 .Search<BlogEntry>(s=>s.Type("posts").Query(...));

So that NEST searches in /blog/posts/_search

这篇关于ElasticSearch NEST客户端不返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆