NEST elasticsearch.NET搜索查​​询不返回结果(第2部分) [英] NEST elasticsearch.NET search query not returning results (part 2)

查看:235
本文介绍了NEST elasticsearch.NET搜索查​​询不返回结果(第2部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NEST的对象初始化器语法来形成搜索查询。当我将第二个pdfQuery与逻辑OR运算符相结合时,我没有得到任何结果。如果我排除它,我会得到结果。

  QueryContainer titleQuery = new MatchQuery 
{
Field = Property .Path< ElasticBook>(p => p.Title),
Query = query,
Boost = 50,
Slop = 2,
MinimumShouldMatch =55%
};

QueryContainer pdfQuery = new MatchQuery
{
Field = Property.Path< ElasticBook>(p => p.Pdf),
Query = query,
CutoffFrequency = 0.001
};

var result = _client.Search< ElasticBook>(new SearchRequest(bookswithstop,en)
{
From = 0,
Size =
Query = titleQuery || pdfQuery,
超时=20000,
Fields = new []
{
Property.Path< ElasticBook>(p => p.Title)
}
});

如果我调试并检查结果var,我复制一个请求属性来获取: / p>

  {
timeout:20000,
from:0,
size:10,
fields:[
title
],
query:{
bool:{
应该:[
{
match:{
title:{
query:Excel 2010的适当指南,
:2,
boost:50.0,
minimum_should_match:55%
}
}
},
{
match:{
pdf:{
query:Excel 2010适当指南,
cutoff_frequency:0.001
}
}
}
]
}
}
}

问题是,如果我将该查询复制到有意义 - 它返回约100个结果(尽管缓慢)。我已经检查了标题信息,这似乎也是正确的从NEST:

  ConnectionStatus = {StatusCode:200,
方法:POST,
Url:http:// elasticsearch-blablablamrfreeman / bookswithstop / en / _search,
请求:{
timeout:20000,
from:0,
size:10,
fields:[
title
],
query:{
bool:{
shoul ...

pdf字段使用弹性搜索附件插件(位于@ https://github.com/elastic/elasticsearch-mapper-attachments ),我正在获得 Newtonsoft.JSON系统。 outofmemoryexceptions 之前(但现在不是因为某些原因)。



因此,我唯一的建议是,也许通过我的查询有一些序列化问题, NEST?如果是这样,我不知道为什么它只能执行一个200代码,并在文档属性中提供0个文档。 p>

有没有人可以向我解释我将如何解决这个问题?它显然不喜欢我的第二个搜索查询(pdfQuery),但我不知道为什么 - 所得到的JSON请求语​​法似乎也是正确的!

解决方案

我认为这部分是导致问题的。

  Fields = new [] 
{
Property.Path< ElasticBook>(p => p.Title)
}

何时使用字段选项,elasticsearch不返回 _source 字段,因此您无法通过 result.Documents 访问结果。相反,您必须使用 result.FieldSelections ,这是非常不愉快的。



如果您只想返回具体您可以使用 result.Documents /reference/current/mapping-source-field.html#include-excluderel =nofollow>来源包含/不包括。使用NEST可以执行以下操作:

  var searchResponse = client.Search< Document>(s => s 
.Source(source => source.Include(f => f.Number))
.Query(q => q.MatchAll()));

希望这有助于您。


I'm using the object initializer syntax with NEST to form a search query. When I include the second pdfQuery with the logical OR operator, I get no results. If I exclude it, I get results.

QueryContainer titleQuery = new MatchQuery
{
    Field = Property.Path<ElasticBook>(p => p.Title),
    Query = query,
    Boost = 50,
    Slop = 2,
    MinimumShouldMatch = "55%"
};

QueryContainer pdfQuery = new MatchQuery
{
    Field = Property.Path<ElasticBook>(p => p.Pdf),
    Query = query,
    CutoffFrequency = 0.001
};

var result = _client.Search<ElasticBook>(new SearchRequest("bookswithstop", "en")
{
    From = 0,
    Size = 10,
    Query = titleQuery || pdfQuery,
    Timeout = "20000",
    Fields = new []
    {
      Property.Path<ElasticBook>(p => p.Title)  
    } 
});

If I debug and inspect the result var, I copy-value one of request properties to get:

{
 "timeout": "20000",
 "from": 0,
 "size": 10,
 "fields": [
   "title"
 ],
 "query": {
   "bool": {
     "should": [
       {
         "match": {
           "title": {
             "query": "Proper Guide To Excel 2010",
             "slop": 2,
             "boost": 50.0,
             "minimum_should_match": "55%"
           }
         }
       },
       {
         "match": {
           "pdf": {
             "query": "Proper Guide To Excel 2010",
             "cutoff_frequency": 0.001
           }
         }
       }
     ]
   }
 }
}

The problem is that if I copy that query into sense - it returns about 100 results (albeit slowly). I've checked the header info and that seems to be correct from NEST as well:

ConnectionStatus = {StatusCode: 200, 
    Method: POST, 
    Url: http://elasticsearch-blablablamrfreeman/bookswithstop/en/_search, 
    Request: {
  "timeout": "20000",
  "from": 0,
  "size": 10,
  "fields": [
    "title"
  ],
  "query": {
    "bool": {
      "shoul...

The pdf field uses the elastic search attachment plugin (located @ https://github.com/elastic/elasticsearch-mapper-attachments) and I was getting Newtonsoft.JSON system.outofmemoryexceptions being thrown before (but not now for some reason).

My only suggestion therefore is that perhaps there's some serialization issue via my query and NEST? If that were the case I'm not sure why it would just execute successfully with a 200 code and give 0 documents in the Documents property

Could anyone please explain to me how I would go about troubleshooting this please? It clearly doesn't like my second search query (pdfQuery) but I'm not sure why - and the resultant JSON request syntax seems to be correct as well!

解决方案

I think this part is causing problems

Fields = new []
    {
      Property.Path<ElasticBook>(p => p.Title)  
    } 

When do you use Fields option, elasticsearch is not returning _source field, so you can't access results through result.Documents. Instead, you have to use result.FieldSelections, which is quite unpleasant.

If you want to return only specific fields from elasticsearch and still be able to use result.Documents you can take advantage of source includes / excludes. With NEST you can do this as follows:

var searchResponse = client.Search<Document>(s => s
    .Source(source => source.Include(f => f.Number))
    .Query(q => q.MatchAll()));

Hope this helps you.

这篇关于NEST elasticsearch.NET搜索查​​询不返回结果(第2部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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