es 单字段多分词器时,textField.keyword无法高亮

2021-01-29 10:15发布

起因:
针对A字段,既需要做分词处理,有需要做聚合统计处理,因此为这个字段配置了多个类型,index和mapping如下

index

"analysis": {
        "analyzer": {
          "comma_analyzer": {
            "tokenizer": "comma"
          },
          "pinyin_analyzer": {
            "tokenizer": "my_pinyin"
          }
        },
        "tokenizer": {
          "comma": {
            "pattern": ",",
            "type": "pattern"
          },
          "my_pinyin": {
            "keep_none_chinese_in_first_letter": "true",
            "lowercase": "true",
            "first_letter": "prefix",
            "keep_original": "true",
            "remove_duplicated_term": "true",
            "keep_first_letter": "true",
            "keep_separate_first_letter": "true",
            "trim_whitespace": "true",
            "type": "pinyin",
            "keep_none_chinese": "true",
            "limit_first_letter_length": "16",
            "keep_full_pinyin": "true"
          }
        }
      }

mapping

"mappings": {
    "service": {
      "properties": {
        "关于中心": {
          "analyzer": "ik_max_word",
          "type": "text",
          "fields": {
            "comma": {
              "fielddata": true,
              "analyzer": "comma_analyzer",
              "type": "text"
            },
            "suggest": {
              "max_input_length": 50,
              "analyzer": "pinyin_analyzer",
              "preserve_position_increments": true,
              "type": "completion",
              "preserve_separators": true
            },
            "keyword": {
              "type": "keyword"
            }
          }
        }
      }
    }
  },

接下来问题出现了,在高亮检索时,使用.keyword进行精确检索和直接使用ik_max_word检索时,【.keyword】不返回高亮字段,请问有大佬知道为什么吗


使用【.keyword】

直接分词

1条回答
爷、活的狠高调
2楼-- · 2021-01-29 10:34

highlight里面加个关于中心.keyword

查看更多
登录 后发表回答