ElasticSearch索引上的多个分析器

bfnvny8b  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(436)

我有一个带有名称字段的索引。我想在这个领域使用soundex分析器和同义词分析器。
我想在一个索引中实现这两个目标。这可能吗?请帮帮我

索引1

{
"settings": {
"index": {
"number_of_shards": "1",
"provided_name": "phonetic_sample",
"creation_date": "1603097131476",
"analysis": {
"filter": {
"my_soundex": {
"replace": "false",
"type": "phonetic",
"encoder": "soundex"
}
},
"analyzer": {
"my_analyzer": {
"filter": [
"lowercase",
"my_soundex"
],
"tokenizer": "standard"
}
}
}

我询问凯瑟琳并匹配凯瑟琳,凯瑟琳和凯瑟琳

索引2

{
"settings": {
"index": {
"number_of_shards": "1",
"provided_name": "phonetic_synonym",
"creation_date": "1603121439096",
"analysis": {
"filter": {
"synonym": {
"format": "wordnet",
"type": "synonym",
"synonyms": [
"s(100000001,1,'Bill',v,1,0).",
"s(100000001,2,'William',v,1,0).",
"s(100000001,3,'Wilhelm',v,1,0)."
]
}
},
"analyzer": {
"synonym": {
"filter": [
"synonym"
],
"tokenizer": "whitespace"
}
}
}

我询问比尔,匹配比尔,威廉和威廉

u0njafvf

u0njafvf1#

您可以将多个字段与多个分析器一起使用。可以为 name 字段,每个字段使用不同的分析器。
下面是修改后的索引Map。
索引Map:

{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "my_soundex": {
            "type": "phonetic",
            "encoder": "metaphone",
            "replace": false
          },
          "synonym": {
            "format": "wordnet",
            "type": "synonym",
            "synonyms": [
              "s(100000001,1,'Bill',v,1,0).",
              "s(100000001,2,'William',v,1,0).",
              "s(100000001,3,'Wilhelm',v,1,0)."
            ]
          }
        },
        "analyzer": {
          "synonym": {
            "filter": [
              "synonym"
            ],
            "tokenizer": "whitespace"
          },
          "my_analyzer": {
            "filter": [
              "lowercase",
              "my_soundex"
            ],
            "tokenizer": "standard"
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "analzyer": "synonym",
        "search_analyzer": "synonym",
        "fields": {
          "content": {
            "type": "text",
            "analyzer": "my_analyzer",
            "search_analyzer": "my_analyzer"
          }
        }
      }
    }
  }
}

那么你可以参考 name 以及 name.content 在您的查询中。您的搜索查询如下:

{
  "query": {
    "multi_match": {
      "query": "Bill",
      "fields": [ 
        "name",
        "name.content"
      ],
      "type": "most_fields" 
    }
  }
}

相关问题