AWS Elastic 搜索:应该对给定查询的所有组合执行搜索

AWS Elastic search : Search should be performed on all combination with given query

我正在研究 AWS Elastic Search。我在我的项目中遇到过一种情况,在我的报告中我必须搜索像 "corona virus".

这样的关键字

但是结果应该包含 "Corona virus" 和 "corona" 以及 "virus" 和 "coronavirus" 等关键字。

请指导我应该如何构建查询 DSL。

注意:使用 PHP 语言。

感谢您的帮助。

//阿米特

您需要使用shingle token filter

A token filter of type shingle that constructs shingles (token n-grams) from a token stream. In other words, it creates combinations of tokens as a single token. For example, the sentence "please divide this sentence into shingles" might be tokenized into shingles "please divide", "divide this", "this sentence", "sentence into", and "into shingles".

映射

PUT index91
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "shingle_filter"
          ]
        }
      },
      "filter": {
        "shingle_filter": {
          "type": "shingle",
          "min_shingle_size": 2,
          "max_shingle_size": 3,
          "output_unigrams": true,
           "token_separator": ""
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}

数据:

POST index91/_doc
{
  "title":"corona virus"
}

查询:

GET index91/_search
{
  "query": {
    "match": {
      "title": "coronavirus"
    }
  }
}

结果:

"hits" : [
      {
        "_index" : "index91",
        "_type" : "_doc",
        "_id" : "gNmUZHEBrJsHVOidaoU_",
        "_score" : 0.9438393,
        "_source" : {
          "title" : "corona virus"
        }
      }

它也适用于 "corona"、"corona virus"、"virus"