当前位置: 首页 > news >正文

ES中的数据类型学习之ARRAY

Arrays | Elasticsearch Guide [7.17] | Elastic

中文翻译 :Array · Elasticsearch 5.4 中文文档 · 看云

Arrays

In Elasticsearch, there is no dedicated array data type. Any field can contain zero or more values by default, however, all values in the array must be of the same data type. For instance:

  • an array of strings: [ "one", "two" ]
  • an array of integers: [ 1, 2 ]
  • an array of arrays: [ 1, [ 2, 3 ]] which is the equivalent of [ 1, 2, 3 ]
  • an array of objects: [ { "name": "Mary", "age": 12 }, { "name": "John", "age": 10 }]

NOTE

Arrays of objects

Arrays of objects do not work as you would expect: you cannot query each object independently of the other objects in the array. If you need to be able to do this then you should use the nested data type instead of the object data type.

This is explained in more detail in Nested.

主要说了

1.es里没有专用的array类型,实际类型是keyword 或者object类型。

2.es的array只能存相同类型的数据

3.es这里的数组不是真正的数组,如果要用真正的数组,推荐用nested数据类型。

还有一些就不复制粘贴了。直接实战开始

PUT my-index-000001/_doc/1
{
  "message": "some arrays in this document...",
  "tags":  [ "elasticsearch", "wow" ],
  "lists": [
    {
      "name": "prog_list",
      "description": "programming list"
    },
    {
      "name": "cool_list",
      "description": "cool stuff list"
    }
  ]
}

PUT my-index-000001/_doc/2
{
  "message": "no arrays in this document...",
  "tags":  "elasticsearch",
  "lists": {
    "name": "prog_list",
    "description": "programming list"
  }
}

PUT my-index-000001/_doc/2
{
  "message": "no arrays in this document...",
  "tags":  "elasticsearch",
  "lists": {
    "name": "prog_list",
    "description": "programming list"
  }
}

查看下映射 GET my-index-000001/_mapping

发现属性实际为keyword 和properties

 测试下查询

GET my-index-000001/_search
{
  "query": {
    "match": {
      "tags": "elasticsearch"
    }
  }
}

发现查出两条数据没有问题。

但是查询 对象中的多个属性的时候就会出现问题

GET my-index-000001/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "lists.name": "prog_list" } },
        {"match": {"lists.description": "cool stuff list"}
        }
      ]
    }
  }
}

这个时候就需要用到nested了。

 

相关文章:

  • ChatGPT:宽列数据库是什么?
  • 环境搭建-Docker搭建MySQL
  • webrtc 音频设备操作之opensl与jni
  • [K8S] K8S资源控制器Controller Manager(4)
  • zabbix添加钉钉告警机器人使用bash和python两种脚本
  • 操作系统概念(黑皮书)阅读笔记
  • 集成千兆网口(Gigabit Ethernet Port)的作用主要是提供高速的有线网络连接,其工作原理涉及以下几个关键点:
  • K8S 部署peometheus + grafana 监控
  • 【linux】Shell脚本三剑客之sed命令的详细用法攻略
  • 【MATLAB APP】建立独立桌面APP
  • 相反多位数
  • Python 教程(三):字符串特性大全
  • ATF-541M4全解析(一)
  • 展馆导览系统架构解析,从需求分析到上线运维
  • json数据格式 继续学习
  • 【5+】跨webview多页面 触发事件(二)
  • 【剑指offer】让抽象问题具体化
  • ➹使用webpack配置多页面应用(MPA)
  • Akka系列(七):Actor持久化之Akka persistence
  • canvas 五子棋游戏
  • canvas绘制圆角头像
  • Centos6.8 使用rpm安装mysql5.7
  • IP路由与转发
  • LintCode 31. partitionArray 数组划分
  • Vultr 教程目录
  • 阿里云购买磁盘后挂载
  • 仿天猫超市收藏抛物线动画工具库
  • 简单实现一个textarea自适应高度
  • 经典排序算法及其 Java 实现
  • 全栈开发——Linux
  • 微信小程序实战练习(仿五洲到家微信版)
  • 小程序开发中的那些坑
  • puppet连载22:define用法
  • raise 与 raise ... from 的区别
  • zabbix3.2监控linux磁盘IO
  • 翻译 | The Principles of OOD 面向对象设计原则
  • 分布式关系型数据库服务 DRDS 支持显示的 Prepare 及逻辑库锁功能等多项能力 ...
  • (175)FPGA门控时钟技术
  • (4)(4.6) Triducer
  • (C语言)fread与fwrite详解
  • (JSP)EL——优化登录界面,获取对象,获取数据
  • (附源码)spring boot网络空间安全实验教学示范中心网站 毕业设计 111454
  • (强烈推荐)移动端音视频从零到上手(上)
  • (三)Hyperledger Fabric 1.1安装部署-chaincode测试
  • (转) Face-Resources
  • (转)C#调用WebService 基础
  • .NET 发展历程
  • .net 连接达梦数据库开发环境部署
  • .net 设置默认首页
  • .NET/C# 项目如何优雅地设置条件编译符号?
  • .NET开发不可不知、不可不用的辅助类(三)(报表导出---终结版)
  • .NET开源全面方便的第三方登录组件集合 - MrHuo.OAuth
  • .NET中winform传递参数至Url并获得返回值或文件
  • @RequestMapping 的作用是什么?
  • [ Algorithm ] N次方算法 N Square 动态规划解决