了解 ignore_above 参数对 Elasticsearch 中磁盘使用的影响

在 Elasticsearch 中,ignore_above 参数允许你忽略(而不是索引)长于指定长度的字符串。 这对于限制字段的大小以避免性能问题很有用。 在本文中,我们将探讨 "ignore_above" 参数如何影响 Elasticsearch 中字段的大小,并将比较两个不同的 ignore_above 参数之间的磁盘使用情况。

首先,我们创建一个名为 "test_index" 的索引,其中包含三个字段:"field_ignore_above_4"、"field_ignore_above_256" 和 "field_ignore_above_512"。 每个字段的类型都是 "keyword",并且具有不同的 "ignore_above" 设置:

复制代码
PUT test_index
{
  "mappings": {
    "properties": {
       "field_ignore_above_4": {
        "type": "keyword",
        "ignore_above": 4
      },
      "field_ignore_above_256": {
        "type": "keyword",
        "ignore_above": 256
      },
      "field_ignore_above_512": {
        "type": "keyword",
        "ignore_above": 512
      }
    }
  }
}

接下来,我们将文档插入到 `test_index` 中:

复制代码
PUT test_index/_doc/1
{
  "field_ignore_above_4": "some value",
  "field_ignore_above_256": "some value",
  "field_ignore_above_512": "some value"
}

当我们对 "test_index" 执行搜索时,我们可以看到 "field_ignore_above_4" 被忽略,因为它的值超出了 "ignore_above" 限制:

复制代码
GET test_index/_search

响应显示 "field_ignore_above_4" 被忽略。这是因为 "some value" 的字符串长度超过 4。

我们做如下的查询:

复制代码
GET test_index/_search
{
  "query": {
    "term": {
      "field_ignore_above_256": {
        "value": "some value"
      }
    }
  }
}

上面显示是有一个文档的。我们如下针对字段 field_ignore_above_4 来做查询:

复制代码
GET test_index/_search
{
  "query": {
    "term": {
      "field_ignore_above_4": {
        "value": "some value"
      }
    }
  }
}

上面是不显示任何的文档的。这说明这个 field_ignore_above_4 字段确实是被忽略了。

现在,我们可以使用 "_disk_usage" API 计算字段的大小:

复制代码
POST /test_index/_disk_usage?run_expensive_tasks=true&filter_path=**.fields.field*

响应提供有关每个字段大小的详细信息:

复制代码
{
  "test_index": {
    "fields": {
      "field_ignore_above_256": {
        "total": "30b",
        "total_in_bytes": 30,
        "inverted_index": {
          "total": "19b",
          "total_in_bytes": 19
        },
        "stored_fields": "0b",
        "stored_fields_in_bytes": 0,
        "doc_values": "11b",
        "doc_values_in_bytes": 11,
        "points": "0b",
        "points_in_bytes": 0,
        "norms": "0b",
        "norms_in_bytes": 0,
        "term_vectors": "0b",
        "term_vectors_in_bytes": 0,
        "knn_vectors": "0b",
        "knn_vectors_in_bytes": 0
      },
      "field_ignore_above_512": {
        "total": "30b",
        "total_in_bytes": 30,
        "inverted_index": {
          "total": "19b",
          "total_in_bytes": 19
        },
        "stored_fields": "0b",
        "stored_fields_in_bytes": 0,
        "doc_values": "11b",
        "doc_values_in_bytes": 11,
        "points": "0b",
        "points_in_bytes": 0,
        "norms": "0b",
        "norms_in_bytes": 0,
        "term_vectors": "0b",
        "term_vectors_in_bytes": 0,
        "knn_vectors": "0b",
        "knn_vectors_in_bytes": 0
      }
    }
  }
}

从响应中,我们可以看到 field_ignore_above_256 和 field_ignore_above_512 的总大小相同,均为 30 字节。

有趣的是,"field_ignore_above_4" 不包含在磁盘使用统计信息中,因为它在索引过程中由于 "ignore_above" 设置而被忽略。 这演示了如何使用 "ignore_above" 参数来控制字段的大小并优化 Elasticsearch 存储的使用。

相关推荐
mazhafener1232 小时前
智慧照明:集中控制器、单双灯控制器与智慧灯杆网关的高效协同
大数据
打码人的日常分享2 小时前
物联网智慧医院建设方案(PPT)
大数据·物联网·架构·流程图·智慧城市·制造
Lansonli3 小时前
大数据Spark(六十一):Spark基于Standalone提交任务流程
大数据·分布式·spark
Rverdoser5 小时前
电脑硬盘分几个区好
大数据
傻啦嘿哟5 小时前
Python 数据分析与可视化实战:从数据清洗到图表呈现
大数据·数据库·人工智能
Theodore_10225 小时前
大数据(2) 大数据处理架构Hadoop
大数据·服务器·hadoop·分布式·ubuntu·架构
簌簌曌6 小时前
CentOS7 + JDK8 虚拟机安装与 Hadoop + Spark 集群搭建实践
大数据·hadoop·spark
冒泡的肥皂7 小时前
强大的ANTLR4语法解析器入门demo
后端·搜索引擎·编程语言
Theodore_10228 小时前
大数据(1) 大数据概述
大数据·hadoop·数据分析·spark·hbase
Aurora_NeAr8 小时前
Apache Spark详解
大数据·后端·spark