首页 > 解决方案 > Elasticsearch 快速矢量荧光笔 (FVH) 不返回“高亮”对象字段

问题描述

以下查询——

GET /<my-index>/_search?pretty
{
    "query": {
        "bool": {
            "should": [
                {
                    "query_string": {
                        "query": "blah blah*"
                    }
                }
            ],
            "must": {
                "bool": {
                    "should": [
                        {
                            "match": {
                                "<some-category>": "foo"
                            }
                        }
                    ]
                }
            }
        }
    },
    "highlight": {
      "pre_tags": [
          ""
      ],
      "post_tags": [
          ""
      ],
      "fields": {
          "*": {
            "type": "plain"
          }
      }
    },
    "_source": false,
    "size": 200
}

返回以下结构的对象——

{
  "took" : 2570,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 6086,
      "relation" : "eq"
    },
    "max_score" : 19.051311,
    "hits" : [
      {
        "_index" : "quotient_aod",
        "_type" : "_doc",
        "_id" : "YCYekXoBP0GFKIFvzFYe",
        "_score" : 19.051311,
        "highlight" : {
          "product_desc" : [
            "..."
          ],...
        }
      },...
...
}

注意highlight属性的存在。以下查询的响应中缺少该属性-

GET /<my-index>/_search?pretty
{
    "query": {
        "bool": {
            "should": [
                {
                    "query_string": {
                        "query": "blah blah*"
                    }
                }
            ],
            "must": {
                "bool": {
                    "should": [
                        {
                            "match": {
                                "<some-category>": "foo"
                            }
                        }
                    ]
                }
            }
        }
    },
    "highlight": {
      "pre_tags": [
          ""
      ],
      "post_tags": [
          ""
      ],
      "fields": {
          "*": {
            "type": "fvh"
          }
      }
    },
    "_source": false,
    "size": 200
}

回复:

{
  "took" : 184,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 6086,
      "relation" : "eq"
    },
    "max_score" : 19.051311,
    "hits" : [
      {
        "_index" : "quotient_aod",
        "_type" : "_doc",
        "_id" : "YCYekXoBP0GFKIFvzFYe",
        "_score" : 19.051311
      },...
    ...
}

请注意,在plainfvh请求中的命中是相同的。ids(YCYekXoBP0GFKIFvzFYe在本例中是第一个)在两个响应中对应。但是,正如我所说,荧光笔请求highlight的响应中缺少 object 属性。fvh这是为什么?

标签: elasticsearch

解决方案


推荐阅读