弹性搜索请求的首字母缩略词

acronyms on Elastic Search request


拜托,我有一个关于弹性搜索的请求,我正在尝试在请求中添加一个首字母缩略词(或同义词)列表。但我不知道该把它放在哪里。 假设同义词列表是 {'HR': 'Human Ressources", "AWS": "Amazon Web Service"}

请求如下:
{
    "query": {
        "bool": {
            "filter": [
                {
                    "terms": {
                        "observatory": [
                            "rome",
                            "meban",
                            "emass",
                            "cigref",
                            "opiiec",
                            "null"
                        ]
                    }
                },
                {
                    "terms": {
                        "referentiel_id": [
                            "null",
                            42,
                            48,
                            52
                        ]
                    }
                }
            ],
            "must": {
                "match": {
                    "skill": {
                        "query": "*dactif*",
                        "fuzziness": "AUTO"
                    }
                }
            }
        }
    }
}

您可以使用 synonym token filter 来处理搜索查询中的同义词

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

索引映射:

{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "synonym": {
            "tokenizer": "whitespace",
            "filter": [
              "synonym"
            ]
          }
        },
        "filter": {
          "synonym": {
            "type": "synonym",
            "synonyms": [
              "HR, Human Ressources",
              "AWS, Amazon Web Service"
            ]
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "observatory": {
        "type": "text",
        "analyzer": "synonym"
      }
    }
  }
}

索引数据:

{
    "observatory":"HR"
}
{
    "observatory":"Human Ressources"
}

搜索查询:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "observatory": {
              "query": "HR"
            }
          }
        }
      ]
    }
  }
}

搜索结果:

 "hits": [
      {
        "_index": "67707925",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.487735,
        "_source": {
          "observatory": "Human Ressources"
        }
      },
      {
        "_index": "67707925",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.487735,
        "_source": {
          "observatory": "HR"
        }
      }
    ]