Elasticsearch 7 : 数组、date

在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" : [
            "学校"
          ]
        }
      }
    ]
  }
}

在ES中,date类型不可为NULL值,因此不允许有这样的设置:"null_value": "NULL"

ES的nested类型介绍与使用

posted @ 2020-06-15 10:42  961897  阅读(1244)  评论(0编辑  收藏  举报