弹性搜索同义词仅适用于某个字段



我有一个 ES 映射,它有 adjustmentorganizationcountry 字段。我想为这些特定字段定义同义词,例如:

SA => Seasonally Adjusted # for adjustment
SA => Special Analysis # for organization
SA => Kingdom of Saudi Arabia # for country

(注意,这是一个人为的例子,不是真实的数据(

我想这会在索引和查询时发生吗?

如何指定同义词应用于特定字段,以便搜索SA将返回所有包含Seasonally Adjusted的文档 Special Analysis adjustment organizationKingdom of Saudi Arabia country

另外,我可以使用基于嵌套文档的嵌套字段来执行此操作。以便子文档{ type: country, value: SA }{ type: organization, value: SA }{ type: adjustment, value: SA }正常工作?

(ES 2.4(

您可以使用自定义同义词过滤器为所有字段创建自定义分析器

例如

分析器:

        "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
         }

您可以为所有字段创建类似的分析器/过滤器,这将为您的用例提供所需的行为。

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" } } } } }

最新更新