我的ES映射包含adjustment
,organization
和country
字段。我想为这些特定字段定义同义词,例如:
SA => Seasonally Adjusted # for adjustment
SA => Special Analysis # for organization
SA => Kingdom of Saudi Arabia # for country
(注意,这是一个人为的例子,而不是真实的数据)
我猜这会在索引和查询时发生吗?
如何指定同义词应该针对特定字段,以便搜索SA
将返回Seasonally Adjusted
,adjustment
中包含Special Analysis
的所有文档organization
中的Kingdom of Saudi Arabia
或country
?
另外,我可以使用基于嵌套文档的嵌套字段来执行此操作。那么子文档{ type: country, value: SA }
和{ type: organization, value: SA }
以及{ type: adjustment, value: SA }
可以正常工作吗?
(ES 2.4)
答案 0 :(得分:0)
您可以使用自定义同义词过滤器
为所有字段创建自定义分析器例如,
分析器:
"country_text_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"lowercase",
"country_synonym"
]
}
过滤:
"country_synonym" : {
"type" : "synonym",
"synonyms_path": "synonyms/synonyms_countries.txt" //<-- this path is relative to ES_CONFIG location
}
您可以为所有字段创建类似的分析器/过滤器,为您的用例提供所需的行为。
答案 1 :(得分:0)
PUT test_index
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"synonym_adjustment": {
"tokenizer": "whitespace",
"filter": ["lowercase","synonym_adjustment_filter"]
},
"synonym_organization": {
"tokenizer": "whitespace",
"filter": ["lowercase","synonym_organization_filter"]
},
"synonym_country": {
"tokenizer": "whitespace",
"filter": ["lowercase","synonym_country_filter"]
}
},
"filter": {
"synonym_adjustment_filter": {
"type": "synonym",
"synonyms": ["SA => Seasonally Adjusted"]
},
"synonym_organization_filter": {
"type": "synonym",
"synonyms": ["SA => Special Analysis"]
},
"synonym_country_filter": {
"type": "synonym",
"synonyms": ["SA => Kingdom of Saudi Arabia"]
}
}
}
}
},
"mappings": {
"index_type_name": {
"properties": {
"adjustment": {
"type": "text",
"analyzer": "default",
"search_analyzer": "synonym_adjustment"
},
"organization": {
"type": "text",
"analyzer": "default",
"search_analyzer": "synonym_organization"
},
"country": {
"type": "text",
"analyzer": "default",
"search_analyzer": "synonym_country"
}
}
}
}
}