Elastic Search:匹配数组中包含该字段的文档

Elastic Search: matching documents whose array contains this field

我有一个类似这样的文档:

{
name: "bob",
contains: ["a", "b", "c"]
},
{
name: "mary",
contains: ["a", "b"]
},
{
name: "Jason",
contains: ["b"]
}

我想查询所有包含 "a" 的人(bob 和 mary)。如何编写查询?

编辑:

当前查询:

                query: {
                bool: {
                    must: [
                        { match: { exists: "yes" }},
                        { term: {contains: "a"}}
                    ],
                    must_not: [
                        { match: { status: "removed"}}
                    ]

                }
            }

contains 字段中的术语 filter/query,例如 {term: {contains: "a"}} 将为您提供所需的信息。假设您只想匹配满足该条件的任何文档,完整的查询将类似于:

{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "contains": "a"
        }
      }
    }
  }
}     

这是有效的,因为值的数组是单独索引的,如果查询的字段是列表,则术语查询将查找包含包含该值的数组的文档。