突出显示 _all 字段上的匹配结果 [英] Highlighting matched results on _all fields

查看:10
本文介绍了突出显示 _all 字段上的匹配结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望突出显示匹配的结果.如果我提到字段名称并返回突出显示的文本,这对我有用,但是如果我将字段指定为_all",它不会返回任何值.这对我有用:

I want the matched results to be highlighted. This works for me if I mention the field name and it returns the highlighted text, however if I give the field as "_all", it is not returning any value. This works for me:

        curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{
        "highlight":{
                    "fields":{
                             "my_field":{}
                    }
        }
}'

这将返回预期值,如下所示:[highlight] => stdClass Object ([my_field] => Array ([0] => stackoverflow 是技术人员最好的网站))

This returns the expected value as follows: [highlight] => stdClass Object ( [my_field] => Array ( [0] => stackoverflow is the best website for techies ) )

但是当我给出这个时:

        curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{
        "highlight":{
                    "fields":{
                             "_all":{}
                    }
        }
}'

我得到空值/没有结果.

I get null value/no result.

[highlight] => stdClass Object ( [_all] => Array () )

如何让它在任何字段上工作,这样我就不必提及字段名称?

How do I get it to work on any field so that I don't have to mention the field name?

推荐答案

您需要将_all 字段映射为已存储.下面的映射应该可以解决问题.请注意,这会增加索引大小.

You need to map the _all field as stored. The mapping below should do the trick. Note though that this will add to the index size.

{
  "my_type": {
      "_all": {
        "enabled": true,
        "store": "yes"
      }
  }}

这篇关于突出显示 _all 字段上的匹配结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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