在ES中,没有专用的数组类型,任何字段类型都可以变成数组。
示例:
DELETE arr
PUT arr
PUT /arr/_mapping
{
  "properties": {
    "tags": {
      "type": "keyword"
    }
  }
}
# 添加三条记录
POST /arr/_doc
{
  "tags":[]
}
POST  /arr/_doc
{
  "tags": ["学校", "政府"]
}
POST  /arr/_doc
{
  "tags": ["学校"]
}
搜索:
# 搜索
GET /arr/_search
{
  "query": {
    "match": {
      "tags": "学校"
    }
  }
}
# 结果为:
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.21110919,
    "hits" : [
      {
        "_index" : "arr",
        "_type" : "_doc",
        "_id" : "bJbZtXIBB9Te9HiR87Zy",
        "_score" : 0.21110919,
        "_source" : {
          "tags" : [
            "学校",
            "政府"
          ]
        }
      },
      {
        "_index" : "arr",
        "_type" : "_doc",
        "_id" : "bZbZtXIBB9Te9HiR9rau",
        "_score" : 0.21110919,
        "_source" : {
          "tags" : [
            "学校"
          ]
        }
      }
    ]
  }
}
原文:https://www.cnblogs.com/ldy-miss/p/13129575.html