简体   繁体   English

如何使用Elasticsearch NEST使用匹配搜索返回结果?

[英]How do I use Elasticsearch NEST to return results using match search?

I am trying to write a simple console app using C# and NEST to learn more about Elasticsearch. 我正在尝试使用C#和NEST编写一个简单的控制台应用程序,以了解有关Elasticsearch的更多信息。

I can run the following query in Sense (Kibana) 我可以在Sense(Kibana)中运行以下查询

GET /companies/company/_search
{
    "query": {
          "match": {
              "dbaName": "STEAK"
         }
     }
}

and I will get back the following result: 我会得到以下结果:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.15342641,
    "hits": [
      {
        "_index": "companies",
        "_type": "company",
        "_id": "1",
        "_score": 0.15342641,
        "_source": {
          "dbaName": "We do steak",
          "primaryLicenseStatus": "T",
          "primaryLicenseDescription": "Restuarant",
          "lastActivityDate": "2016-06-06T08:25:23.4136549-04:00"
        }
      }
    ]
  }
}

However, when I try to do this query using NEST, I get no results: 但是,当我尝试使用NEST进行此查询时,没有任何结果:

var response = client.Search<Company>(s => s
    .Index(theIndex)
    .Query(q =>
        q.Match(m => m.Field(f => f.DbaName).Query("steak"))
    )
);

UPDATE - I figured it out! 更新-我想通了!
So I feel like I should take this post down since the question has no relevance to the solution. 因此,我觉得我应该删除这篇文章,因为问题与解决方案无关。

Spoiler: My query in NEST is fine. 剧透:我在NEST中的查询很好。

I had created a console app that would start by deleting the index, re-creating it, insert the Company and then search for it. 我创建了一个控制台应用程序,该应用程序将从删除索引,重新创建索引,插入公司然后搜索开始。
The server was not keeping up with my console app and only when I stopped deleting/recreating the index was I able to get the search to work. 服务器没有跟上我的控制台应用程序,只有当我停止删除/重新创建索引时,我才能够使搜索工作。 (facepalm) (facepalm)
If any feel that I should simply delete this thread, let me know in the comments below and I will remove it, but someone may find it helpful. 如果我觉得我应该简单地删除该线程,请在下面的评论中告诉我,我将其删除,但有人可能会发现它很有帮助。

The first step in your debugging process should be to view the request that is being made to ES and compare it with what you're expecting. 调试过程的第一步应该是查看对ES发出的请求,并将其与您的期望进行比较。

Here is a great extension method to get the raw json that was sent to ES: 这是获取发送到ES的原始json的一种很好的扩展方法:

    /// <summary>
    /// Debugging method to get the json that was sent to ES
    /// </summary>
    public static string GetRequestString(this IResponse response)
    {
        var request = response.RequestInformation.Request;
        if (request != null)
        {
            return Encoding.Default.GetString(request);
        }
        return response.RequestInformation.RequestUrl;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ElasticSearch上使用NEST - 如何使用部分填充的对象作为搜索条件 - Using NEST on ElasticSearch - How do i use a partially populated object as a search criteria 我如何使用Nest API 5在Elasticsearch中进行重新索引以从Elastic Search 1.4迁移到ElasticSearch 5 - How can i do reindexing in elasticsearch to migrate from elastic search 1.4 to elasticsearch 5 using Nest api 5 如何使用NEST构造来自多个类型的字段且没有魔术字符串的ElasticSearch搜索 - How do I construct an ElasticSearch search using NEST with fields from multiple types without magic strings 使用NEST的Elasticsearch-无结果 - Elasticsearch using NEST - No Results 如何使用NEST在ElasticSearch嵌套对象中搜索 - How to search in ElasticSearch nested objects using NEST 如何使用NEST为Elasticsearch指定索引? - How do I specify an index for Elasticsearch using NEST? 如何使用NEST准确表示此ElasticSearch查询? - How do I accurately represent this ElasticSearch query using NEST? 如何基于客户端创建分页搜索结果Elasticsearch Nest - How to create pagination based on client.Search results Elasticsearch Nest 使用Nest(Elasticsearch)进行方面搜索 - Facet search using Nest (Elasticsearch) 使用 NEST 使用 ElasticSearch 2.x 搜索多种类型时,如何获得混合结果? - How do you get mixed results when searching multiple types with ElasticSearch 2.x using NEST?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM