ElasticSearch中文拼音后无法高亮

es版本7.6.2

修改前显示效果如下

{
    "took": 18,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 12,
            "relation": "eq"
        },
        "max_score": 9.158138,
        "hits": [
            {
                "_index": "herb",
                "_type": "_doc",
                "_id": "TgCJgIIBvi9Bv3av3GtL",
                "_score": 9.158138,
                "_source": {
                    "alias": [ "矾石", "理石",  "白君", "矾石", "明矾", "羽泽"],
                    "id": 33,
                    "image": "http://www.zhongyoo.com/uploads/allimg/140807/1-140PG1223I92.jpg",
                    "name": "白矾",
                    "text": "{\"中药名\":\"白矾 baifan\",\"别名\":\"矾石、理石、白君、矾石、明矾、羽泽。\",\"英
                },
                "highlight": {
                    "name.pinyin": [
                        "白矾"
                    ]
                }
            },
            {
                ....   
            }
        ]
    }
}

Day 2 - ES 6.x拼音分词高亮爬坑记 - Elastic 中文社区

参考上面这篇文章,对原本的setting进行了修改

"analyzer": {
    "pinyin_analyzer": {
        "tokenizer": "my_pinyin"
    }
},
"tokenizer": {
    "my_pinyin": {
        "type": "pinyin",
        "keep_separate_first_letter": false,
        "keep_full_pinyin": true,
        "keep_original": true,
        "limit_first_letter_length": 16,
        "lowercase": true,
        "ignore_pinyin_offset": false,  //新加的一句
        "remove_duplicated_term": true
    }
}

效果:

ElasticSearch中文拼音后无法高亮_第1张图片

你可能感兴趣的:(elasticsearch,搜索引擎)