如何编写涉及包含所有、包含一个、完全包含和不包含操作的 Elasticsearch 查询?

How to write an Elasticsearch query involving contains-all-of, contains-one-of, contains-exactly and not-contains operations?

我有这样的文件:

{
'body': '',
'date': '',
}

我想获取满足这些条件的文档:

如何创建此查询?

您需要使用布尔查询。重要的是要注意,对于您的 "contains exactly these phrases",它的工作原理取决于您对 body 字段应用了哪些分析器。

https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-bool-query.html

例如:

{
  "query": {
    "bool": {
      "must": [
        {"match": {"body": "a"}},
        {"match": {"body": "b"}},
        {"match": {"body": "c"}},
        {"match_phrase": {"body": "g h i"}},
        {"match_phrase": {"body": "j k l"}}
      ],
      "should": [
        {"match": {"body": "d"}},
        {"match": {"body": "e"}},
        {"match": {"body": "f"}}
      ],
      "must_not": [
        {"match": {"body": "m"}},
        {"match": {"body": "n"}}
      ]
    }
  }
}