本文介绍了你如何调试Nest查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的,我很可能没有像我想象的那样创建我的查询。我的问题更多的是教一个人钓鱼而不是给我一条鱼。但是,我将使用我当前的问题作为一个例子。



我在ElasticSearch中有几个类型为系列的文档。我将在下面存储下面的属性和公共修饰符,只需要查询相关的信息:

  class Series 
{
string Id {get; set;}
DateTime StartDate {get; set;}
DateTime EndDate {get; set;}
HashSet< Role>可释放到{get; set;}
}

这些都很好,很花哨。我可以 Get() a 系列对象没有问题。我遇到的问题是想知道Nest如何格式化我的查询。我的直接目标是找到最新的系列,它可以释放到 Role.Visitor 。我设置了这样的Nest查询:

  ISearchResponse<系列> response = client 
.Search< Series>(r =>
r.Filter(f =>
f.Term< Role>(t => t.ReleasableTo.First ),Role.Visitor))
.SortDescending(ser => ser.EndDate).Size(1));

在我看来,这应该是产生一个过滤该系列的查询,所以它只考虑是 ReleasableTo 我的 Role.Visitor ,按结束日期进行排序,并将结果限制为返回的结果。这将是我想要的。在数以千计的系列纪录中,约有90%符合此档案。不幸的是,查询返回0个结果。没有错误,只是没有结果。我不知道的是,如果我正在使用API​​,如果Nest正在生成一个没有意义的查询结构,或者我根本就不了解ElasticSearch。当我删除 Filter 子句时,我得到一个结果,但不能保证每个人都可以看到它。



如何查看Nest生成并发送给ElasticSearch的JSON?

解决方案

您可以获取搜索请求URL的值和JSON请求正文,如下所示:

  var requestURL = response.RequestInformation.RequestUrl; 
var jsonBody = Encoding.UTF8.GetString(response.RequestInformation.Request);

您可以在 RequestInformation 中找到其他有用的属性用于调试。


I'm new to Nest, and I very likely am not creating my query like I think I am. My question is more along the lines of teach a man to fish rather than give me a fish. However, I'll use my current problem as an example.

I have several documents in ElasticSearch of the type Series. I'll stub it out below without the attributes and public modifiers with just the information pertinent to the query:

class Series
{
    string Id {get; set;}
    DateTime StartDate {get; set;}
    DateTime EndDate {get; set;}
    HashSet<Role> ReleasableTo {get; set;}
}

These are all fine and dandy. I can Get() a Series object no problem. The problem I'm running into is trying to figure out how Nest is formatting my query. My immediate goal is to find the most recent Series that is releasable to Role.Visitor. I set up the Nest query like this:

ISearchResponse<Series> response = client
    .Search<Series>(r => 
         r.Filter(f => 
             f.Term<Role>(t=>t.ReleasableTo.First(), Role.Visitor))
    .SortDescending(ser => ser.EndDate).Size(1));

In my mind, this should be producing a query that filters the Series so it only considers the ones that are ReleasableTo my Role.Visitor, reverse sorts by end date, and limits the results to one returned. That would be exactly what I want. In the multiple thousands of records I have for Series, about 90% fit this profile. Unfortunately the query returns 0 results. There is no error, just no results. What I don't know is if I'm using the API incorrectly, if Nest is producing a query structure that doesn't make sense, or I simply don't know ElasticSearch well enough. When I remove the Filter clause I get a result, but I'm not guaranteed everyone is allowed to see it.

How do I view the JSON that Nest produces and sends to ElasticSearch?

解决方案

You can get the values of search request URL and JSON request body as under:

var requestURL = response.RequestInformation.RequestUrl;
var jsonBody = Encoding.UTF8.GetString(response.RequestInformation.Request);

You can find other useful properties in RequestInformation for debugging.

这篇关于你如何调试Nest查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 23:34