简体   繁体   English

Elasticsearch-在_source中排除的突出显示中包含字段

[英]Elasticsearch - Include fields in highlight excluded in _source

I know objects marked as excluded in the _source mapping can be included in the search query. 我知道_source映射中标记为排除的对象可以包含在搜索查询中。 But I have a requirement to include matching terms in the highlight section of the response. 但是我要求在响应的突出显示部分中包含匹配的术语。

eg I have a mapping like: 例如我有一个像这样的映射:

{
  "mappings": {
    "doc": {
      "_source": {
        "excludes": ["some_nested_object.complex_tags_object"]
      },
      "properties": {
        "some_nested_object": {
          "type": "nested"
        }
      }
    }
  }
}

Search Query: 搜索查询:

GET my_index/_search {
    "size": 500,
    "query": {
        "bool": {
            "must": [{
                    "nested": {
                        "query": {
                            "bool": {
                                "must": 
                                [{
                                    "match_phrase_prefix": {
                                        "some_nested_object.complex_tags_object.name": {
                                            "query": "account"
                                        }
                                    }
                                }
                                ]
                            }
                        },
                        "path": "some_nested_object"
                    }
                }
            ]
        }
    },  
    "highlight": {
        "pre_tags": [
            ""
        ],
        "post_tags": [
            ""
        ],
        "fields": {
            "some_nested_object.complex_tags_object.name": {}
        }
    }
}

If I don't exclude in the mapping but in the search query at runtime then I am able to return matching terms in the highlight section but the response is very slow due to the large size of the object. 如果我不在运行时在映射中而是在搜索查询中排除,则可以在突出显示部分中返回匹配的术语,但是由于对象较大,因此响应速度很慢。

So is it possible to include fields marked as exclude in the mapping/doc/_source as part of highlight ? 那么是否有可能在mapting / doc / _source中包含标记为exclude字段作为突出显示的一部分?

So is it possible to include fields marked as exclude in the mapping/doc/_source as part of highlight? 因此,是否可以在mapping / doc / _source中包含标记为排除的字段作为突出显示的一部分?

The short answer to your question unfortunately is no . 不幸的是,对您的问题的简短回答是“ 否” From the Elasticsearch highlighting documentation : 从Elasticsearch 突出显示的文档中

Highlighting requires the actual content of a field. 突出显示需要字段的实际内容。 If the field is not stored (the mapping does not set store to true ), the actual _source is loaded and the relevant field is extracted from _source . 如果未存储该字段(映射未将store设置为true ),则会加载实际的_source ,并从_source提取相关的字段。

You have a few options, each of which involve compromise: 您有几个选择,每个选择都涉及折衷:

  • Include your field back into the source if you absolutely need to support highlighting over it (I appreciate this will conflict with the reasons for excluding it from the source in the first place) 如果您绝对需要支持突出显示字段,则将其重新添加到源中(我很高兴这与首先将其从源中排除的原因相冲突)
  • Relax the requirement to support highlighting over this field (compromise on features) 放宽支持以突出显示该字段的要求(损害功能)
  • Implement a highlighting feature for this field outside Elasticsearch (probably this will compromise on quality of your solution and perhaps cost) 在Elasticsearch之外为此字段实现突出显示功能(可能会影响解决方案的质量,甚至降低成本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM