[英]synonym state name match in Elastic search
我正在使用弹性搜索将位置匹配到弹性搜索索引。
弹性搜索索引数据样本
{
"_index": "reference_2",
"_type": "geonames",
"_id": "AUn2LNJlZ8pWP0iSxZYS",
"_version": 1,
"_score": 1,
"_source": {
"geoNameId": "7509382",
"lat": "34.64274",
"longi": "64.51122",
"timeZoneId": "Asia/Kabul",
"countryCode": "AF",
"state": "Tamil nadu",
"timezone": "AFT",
"stateCode": "09",
"alterCityName": [
chennai
],
"cityName": "chennai",
"population": "0",
"countryName": "India"
},
"sort": [
1,
"geonames",
"reference_2"
]
}
用户可以将状态写为“泰米尔纳德邦”或泰米尔纳德邦,我希望程序或查询了解泰米尔纳德邦与泰米尔纳德邦相同。 谁能帮我实现这个目标
最简单的方法是定义一个同义词文件,其中包含您要使用的所有同义词。 提供到您的字段的特定映射以使用该特定的同义词文件。
例如,您的同义词文件将包含以下内容,
tamil nadu,tamilnadu,tn => tamilnadu
andhra pradesh,andra,andrhrapradesh,ap => andhrapradesh
将路径pf同义词文件提供给自定义分析,并将其用于您的字段。
"filter": {
"custom_state": {
"type" : "synonym",
"synonyms_path" : "<path to synonym file>"
},
.....
"analyzer": {
"states": {
"type": "custom",
"filter": [ "lowercase", "custom_state"]
},
.......
"properties" : {
"STATE" : {"type" : "string", "analyzer": "states"},
........
使用单独的同义词文件的优点是您以后可以轻松扩展/包含更多值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.