我想做一些关键字的Elasticsearch索引,比如..。标签。并对关键词进行同义词过滤。
我认为索引关键字有两种方式,首先是make keyword
类型。
{
"settings": {
"keywordField": {
"type": "keyword"
}
}
}
如果用League of Legends
建立一个索引,也许这个。
{
"keywordField": ["leagueoflegends", "league", "legends", "lol" /* synonym */]
}
或text
类型:
{
"settings": {
"keywordField": {
"type": "text",
"analyzer": "lowercase_and_whitespace_and_synonym_analyzer"
}
}
}
也许这个。
{
"keywordField": ["league of legends"](synonym: lol => leagueoflegends)
}
如果将_analyzer
api用于此字段,则需要“传奇联盟”、“联盟”、“传奇”。
搜索查询:'lol',‘英雄联盟’,‘英雄联盟’必须匹配这个字段。
哪种练习是最好的?
发布于 2021-03-30 14:50:42
使用索引数据、映射、搜索查询和搜索结果添加一个工作示例。在下面的示例中,我使用了两个同义词lol
和leagueoflegends
索引映射:
{
"settings": {
"index": {
"analysis": {
"filter": {
"synonym_filter": {
"type": "synonym",
"synonyms": [
"leagueoflegends, lol"
]
}
},
"analyzer": {
"synonym_analyzer": {
"filter": [
"lowercase",
"synonym_filter"
],
"tokenizer": "standard"
}
}
}
}
},
"mappings": {
"properties": {
"keywordField": {
"type": "text"
}
}
}
}
索引数据:
{
"keywordField": ["leagueoflegends", "league", "legends"]
}
搜索查询:
{
"query": {
"match": {
"keywordField": {
"query": "lol",
"analyzer": "synonym_analyzer"
}
}
}
}
搜索结果:
"hits": [
{
"_index": "66872989",
"_type": "_doc",
"_id": "1",
"_score": 0.19363807,
"_source": {
"keywordField": [
"leagueoflegends",
"league",
"legends"
]
}
}
]
https://stackoverflow.com/questions/66872989
复制相似问题