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

相关推荐
AA陈超14 分钟前
Lyra学习004:GameFeatureData分析
c++·笔记·学习·ue5·虚幻引擎
无代码专家1 小时前
设备巡检数字化解决方案:构建高效闭环管理体系
java·大数据·人工智能
天远数科1 小时前
Node.js 原生加密指南:详解 Crypto 模块对接天远银行卡黑名单接口
大数据·api
expect7g1 小时前
Paimon Branch --- 流批一体化之二
大数据·后端·flink
zkl_zkl_1 小时前
地理信息系统学习笔记——第六章 空间数据采集与处理
笔记·学习·数据处理·数据质量·空间数据
光头程序员1 小时前
学习笔记——主攻 vite
笔记·学习
零匠学堂20251 小时前
移动学习系统,如何提升企业培训效果?
java·开发语言·spring boot·学习·音视频
天远云服1 小时前
高并发风控实践:AES 加密与银行卡风险标签清洗的 Go 语言实现
大数据·api
无级程序员2 小时前
datasophon中dolpinscheduler的自定义配置common.properties不生效问题解决
大数据
珠海西格电力2 小时前
零碳园区基础架构协同规划:能源-建筑-交通-数字系统的衔接逻辑
大数据·人工智能·智慧城市·能源