[英]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.