Java 如何禁用es突出显示同义词?
我只想突出显示我在查询中搜索的单词,不包括同义词,但我也希望es可以返回搜索结果,可以包含同义词搜索结果,下面是一个示例Java 如何禁用es突出显示同义词?,java,
elasticsearch,elk,Java,
elasticsearch,Elk,我只想突出显示我在查询中搜索的单词,不包括同义词,但我也希望es可以返回搜索结果,可以包含同义词搜索结果,下面是一个示例 PUT /my_test_index/ { "settings": { "analysis": { "filter": { "native_synonym": { "type": "synonym", "ignore_
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"
}
}
}
}
但是,es同时突出显示水果
和苹果
,而我只希望苹果
得到突出显示。
有人知道怎么解决这个问题吗?提前感谢:)
“点击次数”:[
{
“_索引”:“我的_测试_索引”,
“\u类型”:“\u单据”,
“_id”:“RMyZrXAB7JsJEwsbVF33”,
“_分数”:0.29171452,
“_来源”:{
“描述”:“苹果”
},
“亮点”:{
“描述”:[
“苹果”
]
}
},
{
“_索引”:“我的_测试_索引”,
“\u类型”:“\u单据”,
“_id”:“RcyarXAB7JsJEwsboF2V”,
“_分数”:0.29171452,
“_来源”:{
“描述”:“水果”
},
“亮点”:{
“描述”:[
“水果”
]
}
}
]
您可以添加行为与实际搜索查询不同的突出显示查询。然后,您只需要一个没有同义词的索引字段,就可以得到您想要的:
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",
"fields": {
"raw": {
"type": "text",
"analyzer": "whitespace"
}
}
}
}
}
}
GET /my_test_index/_search
{
"query": {
"match": {
"desc": "apple"
}
},
"highlight": {
"fields": {
"desc.raw": {
"highlight_query": {
"match": {
"desc.raw": "apple"
}
}
}
}
}
}
GET /my_test_index/_search
{
"query": {
"match": {
"desc": "apple"
}
},
"highlight": {
"fields": {
"desc": {}
}
}
}
"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>"
]
}
}
]
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",
"fields": {
"raw": {
"type": "text",
"analyzer": "whitespace"
}
}
}
}
}
}
GET /my_test_index/_search
{
"query": {
"match": {
"desc": "apple"
}
},
"highlight": {
"fields": {
"desc.raw": {
"highlight_query": {
"match": {
"desc.raw": "apple"
}
}
}
}
}
}