身安不如心安,屋宽不如心宽 。

高亮问题:部分匹配却高亮了整体

Elasticsearch | 作者 Morry | 发布于2019年12月20日 | 阅读数:3634

ES版本:5.3.0
插件:ik

重现步骤:
PUT test123
{
"mappings": {
"test123": {
"properties": {
"text": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}
}
}

POST test123/test123
{
"text": "中华人民共和国"
}

GET test123/_search
{
"query": {
"match": {
"text": "中华共和"
}
},
"highlight": {
"fields": {
"text": {}
}
}
}

# result
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.5446649,
"hits": [
{
"_index": "test123",
"_type": "test123",
"_id": "AW8jP3nilfYoZZrT2IfC",
"_score": 0.5446649,
"_source": {
"text": "中华人民共和国"
},
"highlight": {
"text": [
"<em>中华人民共和</em>国"
]
}
}
]
}
}

如上,搜的是`中华共和`,但把`人民`也一起高亮了
已邀请:

Charele - Cisco4321

赞同来自:

你什么版本的ES啊?我的测试结果
 
{
  "took" : 45,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.5753642,
    "hits" : [
      {
        "_index" : "test123",
        "_type" : "_doc",
        "_id" : "-xL1Jm8BhQozQBe4JN2L",
        "_score" : 0.5753642,
        "_source" : {
          "text" : "中华人民共和国"
        },
        "highlight" : {
          "text" : [
            "<em>中华</em>人民<em>共和</em>国"
          ]
        }
      }
    ]
  }
}

- Elasticsearch,php

赞同来自:

这个和分词词库有关

要回复问题请先登录注册