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了。

相关推荐
ACP广源盛1392462567312 小时前
破局 PCIe 4.0 交换瓶颈@ACP#IX8024 / ASM58024参数及应用对比
大数据·人工智能·分布式·嵌入式硬件
南讯股份Nascent13 小时前
颖通电商全渠道项目启动会成功举办
大数据·人工智能·物联网
猴子155168113 小时前
问卷逻辑跳转功能谁更强?2026年四款工具条件设置实测
大数据
Elastic 中国社区官方博客13 小时前
使用 Elasticsearch 作为 Grafana 的直接替代 Prometheus 后端
大数据·数据库·sql·elasticsearch·搜索引擎·grafana·prometheus
XTIOT66613 小时前
CRPT 诚实标识采集落地技术实践:分工况硬件选型与合规数据标准化解决方案
大数据·运维·人工智能·嵌入式硬件·物联网
杨婷12313 小时前
2026 企业微信会话存档服务商选型指南:一维助手方案深度解析
大数据·数据库·企业微信
网络与设备以及操作系统学习使用者13 小时前
通信的物理与逻辑双维度解析
学习·深度优先
浩瀚地学14 小时前
【Java基础复习】IO流(二)
java·开发语言·经验分享·笔记·学习
2301_7803567014 小时前
全视通智慧医院解决方案:构建数智化医疗新生态
大数据·网络·人工智能
researcher-Jiang14 小时前
Manacher算法学习与应用
c++·学习·算法