使用 Ngram 分析器对索引进行匹配查询时,ElasticSearch 突出显示失败

ElasticSearch Highlighting fails on match queries against index with Ngram Analyzer

我创建了一个索引,并在索引和自定义 _all 的所有字段上设置了 ngram 分析器。在索引了几个文档之后,我试图查询索引以获得类似功能的建议。

查询的输出有 return 个结果,但没有突出显示。

分析仪设置:

"analysis": {
  "analyzer": {
    "my_edgegram_analyzer": {
      "filter": [
        "lowercase"
      ],
      "tokenizer": "my_edge_tokenizer"
    }
  },
  "tokenizer": {
    "my_edge_tokenizer": {
      "token_chars": [
        "letter",
        "digit",
        "punctuation",
        "symbol"
      ],
      "min_gram": "3",
      "type": "ngram",
      "max_gram": "26"
    }
  }
}

映射:

{
  "st1": {
    "mappings": {
      "a": {
        "_all": {
          "enabled": false
        },
        "dynamic_templates": [
          {
            "catch_all": {
              "match": "imp*",
              "match_mapping_type": "string",
              "mapping": {
                "analyzer": "my_edgegram_analyzer",
                "copy_to": "catch_all",
                "norms": false,
                "type": "text"
              }
            }
          }
        ],
        "properties": {
          "catch_all": {
            "type": "text",
            "store": true,
            "analyzer": "my_edgegram_analyzer"
          },
          "imp_server_id": {
            "type": "text",
            "norms": false,
            "copy_to": [
              "catch_all"
            ],
            "analyzer": "my_edgegram_analyzer"
          },
          "imp_server_name": {
            "type": "text",
            "norms": false,
            "copy_to": [
              "catch_all"
            ],
            "analyzer": "my_edgegram_analyzer"
          }
        }
      },
      "b": {
        "_all": {
          "enabled": false
        },
        "dynamic_templates": [
          {
            "catch_all": {
              "match": "imp*",
              "match_mapping_type": "string",
              "mapping": {
                "analyzer": "my_edgegram_analyzer",
                "copy_to": "catch_all",
                "norms": false,
                "type": "text"
              }
            }
          }
        ],
        "properties": {
          "catch_all": {
            "type": "text",
            "store": true,
            "analyzer": "my_edgegram_analyzer"
          },
          "imp_server_id": {
            "type": "text",
            "norms": false,
            "copy_to": [
              "catch_all"
            ],
            "analyzer": "my_edgegram_analyzer"
          },
          "imp_server_name": {
            "type": "text",
            "norms": false,
            "copy_to": [
              "catch_all"
            ],
            "analyzer": "my_edgegram_analyzer"
          }
        }
      }
    }
  }
}

文件:

http://localhost:9200/st1/b/1

{"imp_server_name":"abc1-4-jam9.my.test.com","imp_server_id":"vrock2-us"}

http://localhost:9200/st1/a/1

{"imp_server_name":"abc2-5-ajm9.my.test.com","imp_server_id":"vrock2-us"}

查询:

{
    "query": {
        "match": {
           "catch_all": {
            "query":"test",
            "analyzer": "keyword"
           }
        }

    },
"highlight": {
        "pre_tags": ["<b>"],
        "post_tags": ["</b>"],
    "fields": {
      "*": {}
    },
    "require_field_match": false
 }
}

响应:

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.16292635,
    "hits": [
      {
        "_index": "st1",
        "_type": "a",
        "_id": "1",
        "_score": 0.16292635,
        "_source": {
          "imp_server_name": "abc2-5-ajm9.my.test.com",
          "imp_server_id": "vrock2-us"
        },
        "highlight": {
          "imp_server_name": [
            "abc2-5-ajm9.my.test.com"
          ],
          "catch_all": [
            "abc2-5-ajm9.my.test.com"
          ]
        }
      },
      {
        "_index": "st1",
        "_type": "b",
        "_id": "1",
        "_score": 0.16292635,
        "_source": {
          "imp_server_name": "abc1-4-jam9.my.test.com",
          "imp_server_id": "vrock2-us"
        },
        "highlight": {
          "imp_server_name": [
            "abc1-4-jam9.my.test.com"
          ],
          "catch_all": [
            "abc1-4-jam9.my.test.com"
          ]
        }
      }
    ]
  }
}

在上述情况下如何使突出显示工作。以下是预期的输出:

预期输出:

"highlight": {
  "imp_server_name": [
    "abc2-5-ajm9.my.<b>test</b>.com"
  ],
  "catch_all": [
    "abc2-5-ajm9.my.<b>test</b>.com"
  ]
}

我能够通过在架构中设置 term_vector 来获得结果。

 "term_vector": "with_positions_offsets"