Elk highlight synonym problem

Hi, I am using elasticsearch 6.x version and I have problem when gettiing highlight result with synonym.

PUT /my_test_index/
{
    "settings": {
        "analysis": {
            "filter": {
                "native_synonym": {
                    "type": "synonym",
                    "ignore_case": true,
                    "expand": true,
                    "synonyms": [
                        "apple,fruit"
                    ]
                }
            },
            "analyzer": {
                "test_analyzer": {
                    "tokenizer": "whitespace",
                    "filter": [
                        "native_synonym"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "desc": {
                "type": "text",
                "analyzer": "test_analyzer"
            }
        }
    }
}

when I search keywords apple with desc fields highlight

{
    "query": {
    	"match": {
    		"desc": "apple"
    	}
    },
    "highlight": {
    	"fields": {
    		"desc": {}
    	}
    }
}

I got both apple and fruit highlight, however I only want the words apple highlight because what I search in the query is the word apple

"hits": [
            {
                "_index": "my_test_index",
                "_type": "_doc",
                "_id": "RMyZrXAB7JsJEwsbVF33",
                "_score": 0.29171452,
                "_source": {
                    "desc": "apple"
                },
                "highlight": {
                    "desc": [
                        "<em>apple</em>"
                    ]
                }
            },
            {
                "_index": "my_test_index",
                "_type": "_doc",
                "_id": "RcyarXAB7JsJEwsboF2V",
                "_score": 0.29171452,
                "_source": {
                    "desc": "fruit"
                },
                "highlight": {
                    "desc": [
                        "<em>fruit</em>"
                    ]
                }
            }
        ]

Anyone knows how to solve this? Thanks in advance.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.