ElasticSearch Nest 2.x使用_all搜索突出显示嵌套对象 [英] ElasticSearch Nest 2.x Highlight Nested Object With _all Search

查看:141
本文介绍了ElasticSearch Nest 2.x使用_all搜索突出显示嵌套对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用_all搜索时,似乎无法使嵌套对象突出显示.

I can't seem to get nested objects to highlight when using an _all search.

我的索引:

{
   "settings":{
      "analysis":{
         "analyzer":{
            "nGramAnalyzer":{
               "type":"custom",
               "filter":[
                  "lowercase",
                  "asciifolding",
                  "NGramFilter"
               ],
               "tokenizer":"WhitespaceTokenizer"
            },
            "WhitespaceAnalyzer":{
               "type":"custom",
               "filter":[
                  "lowercase",
                  "asciifolding"
               ],
               "tokenizer":"WhitespaceTokenizer"
            },
         },
         "filter":{
            "NGramFilter":{
               "type":"ngram",
               "min_gram":1,
               "max_gram":20
            }
         },
         "tokenizer":{
            "WhitespaceTokenizer":{
               "type":"whitespace"
            }
         }
      }
   },
   "mappings":{
      "CustomerSearchResult":{
         "_all":{
            "analyzer":"nGramAnalyzer",
            "search_analyzer":"WhitespaceAnalyzer"
         },
         "properties":{
            "customerId":{
               "type":"string",
               "index":"not_analyzed"
            },
            "remarks":{
               "type":"nested",
               "properties":{
                  "remarkId":{
                     "type":"integer"
                  },
                  "customerId":{
                     "type":"integer"
                  },
                  "remarkText":{
                     "type":"string",
                     "index":"analyzed",
                     "analyzer":"nGramAnalyzer",
                     "search_analyzer":"WhitespaceAnalyzer"
                  }
               }
            },
         }
      }
   }
}

我的查询:

{
   "from":0,
   "size":100,
   "highlight":{
      "pre_tags":[
         "<b>"
      ],
      "post_tags":[
         "<b>"
      ],
      "fields":{
         "remarks.remarkText":{

         }
      }
   },
   "_source":{
      "exclude":[
         "remarks"
      ]
   },
   "query":{
      "match":{
         "_all":{
            "query":"test",
            "operator":"and"
         }
      }
   }
}

如果我使用嵌套查询进行查询,我会得到突出显示,但是我需要搜索_all.我曾尝试在父级中设置include,在根中设置include,但这没什么不同.

If I query using a nested query, I do get highlights, but I need to search _all. I've tried setting include in parent, include in root, but it didn't make a difference.

我之所以排除在外,是因为我不想真正返回它们,而只是它们的亮点.我也尝试过不包含排除项的查询.

I'm excluding remarks because I don't want to actually return them, just their highlights. I've tried the query without the exclude as well.

我只需要为嵌套对象加亮显示.

I only need highlights for the nested object.

推荐答案

我必须在突出显示部分使用RequireFieldMatch(false).

I had to use RequireFieldMatch(false) on the highlight.

这篇关于ElasticSearch Nest 2.x使用_all搜索突出显示嵌套对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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