当前位置: 首页 > 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了。

 

http://www.lryc.cn/news/406789.html

相关文章:

  • vue网络请求
  • 几何光学基本原理——费马原理和射线方程
  • OpenCV车牌识别技术详解
  • 解决llama_index中使用Ollama出现timed out 问题
  • Python爬虫技术 第14节 HTML结构解析
  • 【vue3|第18期】Vue-Router路由的三种传参方式
  • ElasticSearch(六)— 全文检索
  • Oracle核心进程详解并kill验证
  • 【BUG】已解决:SyntaxError:positional argument follows keyword argument
  • 怎样在 Nginx 中配置基于请求客户端 Wi-Fi 连接状态的访问控制?
  • 逆向案例二十九——某品威客登录,请求头参数加密,简单webpack
  • 河道高效治理新策略:视频AI智能监控如何助力河污防治
  • [React]如何提高大数据量场景下的Table性能?
  • 基于Vision Transformer的mini_ImageNet图片分类实战
  • JS中map()使用记录
  • JavaWeb学习——请求响应、分层解耦
  • Vue中!.和?.是什么意思
  • 秋招突击——7/22——复习{堆——前K个高频元素}——新作{回溯——单次搜索、分割回文串。链表——环形链表II,合并两个有序链表}
  • android13禁用某个usb设备
  • tmux相关命令
  • 初创小程序公司怎么选服务器合作商
  • 基于微信小程序+SpringBoot+Vue的自习室选座与门禁系统(带1w+文档)
  • 【Linux】进程IO|重定向|缓冲区|dup2|dup|用户级缓冲区|模拟缓冲区
  • bug bug bug
  • 医疗器械上市欧美,需要什么样的网络安全相关申报文件?
  • 【UbuntuDebian安装Nginx】在线安装Nginx
  • Jacoco 单元测试配置
  • App Instance 架构示例
  • 【论文速读】| MoRSE:利用检索增强生成技术填补网络安全专业知识的空白
  • pip install albumentations安装下载超级细水管