ES同义词
程序员文章站
2022-03-08 23:37:10
...
配置mapping
PUT /megacorp
{
"mappings": {
"properties": {
"name":{
"type": "text",
"analyzer": "ik-index"
}
}
},
"settings": {
"analysis": {
"filter": {
"local_synonym" : {
"type" : "synonym",
"synonyms_path" : "synonyms/synonyms.txt"
}
},
"analyzer": {
"ik-index": {
"type": "custom",
"tokenizer": "ik_max_word",
"filter": [
"local_synonym"
]
}
}
}
}
}
可以用以下命令查看,同义词是否配置成功
GET /megacorp/_analyze
{
"analyzer": "ik-index",
"text": "西红柿"
}
添加数据
PUT megacorp/_bulk
{"index":{"_id":"1"}}
{"name":"西红柿"}
{"index":{"_id":"2"}}
{"name":"番茄"}
{"index":{"_id":"3"}}
{"name":"圣女"}
查询西红柿
GET megacorp/_search
{
"query": {
"match": {
"name": "西红柿"
}
}
}
结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 0.24480756,
"hits" : [
{
"_index" : "megacorp",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.24480756,
"_source" : {
"name" : "西红柿"
}
},
{
"_index" : "megacorp",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.24480756,
"_source" : {
"name" : "番茄"
}
},
{
"_index" : "megacorp",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.24480756,
"_source" : {
"name" : "圣女"
}
}
]
}
}
上一篇: 抽象Vue公共组件详解
下一篇: ES6 map集合