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

相关推荐
StickToForever40 分钟前
第4章 信息系统架构(五)
经验分享·笔记·学习·职场和发展
leegong231114 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql
Moonnnn.5 小时前
51单片机学习——动态数码管显示
笔记·嵌入式硬件·学习·51单片机
大数据追光猿5 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
南宫生5 小时前
力扣每日一题【算法学习day.132】
java·学习·算法·leetcode
技术小齐6 小时前
网络运维学习笔记 016网工初级(HCIA-Datacom与CCNA-EI)PPP点对点协议和PPPoE以太网上的点对点协议(此处只讲华为)
运维·网络·学习
竹言笙熙6 小时前
代码审计初探
学习·web安全
日记成书6 小时前
物联网智能项目
物联网·学习
虾球xz6 小时前
游戏引擎学习第118天
学习·游戏引擎
人类群星闪耀时7 小时前
物联网与大数据:揭秘万物互联的新纪元
大数据·物联网·struts