我有一个ES映射,其中包含adjustment、organization和country字段。我希望为这些特定字段定义同义词,例如:
SA => Seasonally Adjusted # for adjustment
SA => Special Analysis # for organization
SA => Kingdom of Saudi Arabia # for country(请注意,这是一个人为的例子,而不是真实的数据)
我猜这在索引和查询时都会发生?
如何指定同义词应用于特定字段,以便搜索SA将返回包含adjustment中的Seasonally Adjusted、organization中的Special Analysis或country中的Kingdom of Saudi Arabia的所有文档
另外,我可以对基于嵌套文档的嵌套字段执行此操作吗?这样子文档{ type: country, value: SA }、{ type: organization, value: SA }和{ type: adjustment, value: SA }就可以正常工作了?
(ES 2.4)
发布于 2017-03-18 10:00:45
您可以使用自定义同义词过滤器为所有字段创建自定义分析器
例如,
分析器:
"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
}您可以为所有字段创建类似的分析器/过滤器,这将为您的用例提供所需的行为。
发布于 2020-01-04 01:51:53
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" } } } } }
https://stackoverflow.com/questions/42864799
复制相似问题