如何在elasticsearch中实现首字母缩略词作为同义词

我的请求中有以下设置:

我的请求中有以下设置:

    var synonyms = [
        "usa, united states of america",
        "oa, other acronym"
    ]
        
    "settings" : {
        "index" : {
            "ysis" : {
                "yzer" : {
                    "synonym" : {
                        "type" : "custom",
                        "tokenizer" : "whitespace",
                        "filter" : ["lowercase", "synonym"]
                    }
                },
                "filter" : {
                    "synonym" : {
                        "type" : "synonym",
                        "lenient": true,
                        "synonyms" : synonyms
                    },
                }
            }
        }
    },
    "search": {
        "size": 50,
        "query": {
            "bool": {
                "should": [
                    {"match": {'ANNOTATIONS': {"query": "usa", boost: 2}}},
                ]
            }
         }
     }

当我在美国搜索时,我需要将美国的结果与美国同等排名

到目前为止,我完全不知所措。有人能帮忙吗?

希望如此,干杯!

1

您还需要在特定字段的映射部分中定义分析器

添加带有索引数据、映射、搜索查询和搜索结果的工作示例

索引映射:

{
  "settings": {
    "index": {
      "ysis": {
        "yzer": {
          "synonym": {
            "tokenizer": "whitespace",
            "filter": [
              "synonym"
            ]
          }
        },
        "filter": {
          "synonym": {
            "type": "synonym",
            "synonyms": [
              "usa, united states of america",
              "ny, new york"
            ]
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "ANNOTATIONS": {
        "type": "text",
        "yzer": "synonym"
      }
    }
  }
}

索引数据:

{
    "ANNOTATIONS":"united states of america"
}
{
    "ANNOTATIONS":"usa"
}

搜索查询:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "ANNOTATIONS": {
              "query": "usa"
            }
          }
        }
      ]
    }
  }
}

搜索结果:

 "hits": [
      {
        "_index": "67274014",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.86133814,
        "_source": {
          "ANNOTATIONS": "usa"
        }
      },
      {
        "_index": "67274014",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.86133814,
        "_source": {
          "ANNOTATIONS": "united states of america"
        }
      }
    ]

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(939)
在Outlook桌面应用程序的后台使用动画gif
上一篇
SQL语句-CHARINDEX无效函数
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(39条)