首页 > 编程语言 > 详细

Elasticsearch 7 : 数组

时间:2020-06-15 11:48:14      阅读:100      评论:0      收藏:0      [点我收藏+]

在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的nested类型介绍与使用

Elasticsearch 7 : 数组

原文:https://www.cnblogs.com/ldy-miss/p/13129575.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!