了解 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" 设置:

json 复制代码
1.  PUT test_index
2.  {
3.    "mappings": {
4.      "properties": {
5.         "field_ignore_above_4": {
6.          "type": "keyword",
7.          "ignore_above": 4
8.        },
9.        "field_ignore_above_256": {
10.          "type": "keyword",
11.          "ignore_above": 256
12.        },
13.        "field_ignore_above_512": {
14.          "type": "keyword",
15.          "ignore_above": 512
16.        }
17.      }
18.    }
19.  }

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

bash 复制代码
1.  PUT test_index/_doc/1
2.  {
3.    "field_ignore_above_4": "some value",
4.    "field_ignore_above_256": "some value",
5.    "field_ignore_above_512": "some value"
6.  }

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

bash 复制代码
GET test_index/_search

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

我们做如下的查询:

bash 复制代码
1.  GET test_index/_search
2.  {
3.    "query": {
4.      "term": {
5.        "field_ignore_above_256": {
6.          "value": "some value"
7.        }
8.      }
9.    }
10.  }

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

bash 复制代码
1.  GET test_index/_search
2.  {
3.    "query": {
4.      "term": {
5.        "field_ignore_above_4": {
6.          "value": "some value"
7.        }
8.      }
9.    }
10.  }

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

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

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

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

json 复制代码
1.  {
2.    "test_index": {
3.      "fields": {
4.        "field_ignore_above_256": {
5.          "total": "30b",
6.          "total_in_bytes": 30,
7.          "inverted_index": {
8.            "total": "19b",
9.            "total_in_bytes": 19
10.          },
11.          "stored_fields": "0b",
12.          "stored_fields_in_bytes": 0,
13.          "doc_values": "11b",
14.          "doc_values_in_bytes": 11,
15.          "points": "0b",
16.          "points_in_bytes": 0,
17.          "norms": "0b",
18.          "norms_in_bytes": 0,
19.          "term_vectors": "0b",
20.          "term_vectors_in_bytes": 0,
21.          "knn_vectors": "0b",
22.          "knn_vectors_in_bytes": 0
23.        },
24.        "field_ignore_above_512": {
25.          "total": "30b",
26.          "total_in_bytes": 30,
27.          "inverted_index": {
28.            "total": "19b",
29.            "total_in_bytes": 19
30.          },
31.          "stored_fields": "0b",
32.          "stored_fields_in_bytes": 0,
33.          "doc_values": "11b",
34.          "doc_values_in_bytes": 11,
35.          "points": "0b",
36.          "points_in_bytes": 0,
37.          "norms": "0b",
38.          "norms_in_bytes": 0,
39.          "term_vectors": "0b",
40.          "term_vectors_in_bytes": 0,
41.          "knn_vectors": "0b",
42.          "knn_vectors_in_bytes": 0
43.        }
44.      }
45.    }
46.  }

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

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

相关推荐
醉颜凉7 小时前
Elasticsearch核心架构:集群(Cluster)原理详解与核心作用
elasticsearch·架构·jenkins
醉颜凉7 小时前
Elasticsearch 深度原理:在保证数据一致性的前提下,如何安全更新倒排索引?
大数据·elasticsearch·搜索引擎
qq_273272619 小时前
oracle JDK 更换 openJDK
elasticsearch
Cx330❀11 小时前
【LangChain】LangChain 核心技术全景指南:从基础入门到 LCEL 链式编程
大数据·elasticsearch·搜索引擎·性能优化·langchain·全文检索
云间月13141 天前
Elasticsearch 数据怎么看?部署 Kibana,从索引查询到可视化图表
大数据·elasticsearch·jenkins
Elasticsearch1 天前
每个搜索团队都需要的三个 SLO:使用 OpenTelemetry 监控搜索延迟、可用性和质量
elasticsearch
OPEN-F1 天前
Python进阶教程:Git版本控制与团队协作
git·python·elasticsearch
玹外之音2 天前
Spring AI + Elasticsearch 向量存储实战:从零构建智能文档检索系统
人工智能·spring·elasticsearch
小闫BI设源码2 天前
Elasticsearch面试必看:如何让客户端精准选择节点高效执行请求?
java·elasticsearch·面试宝典·深入解析
醉颜凉2 天前
Elasticsearch 相关性评分核心解密:tie_breaker 参数作用原理与实战调优全解析
大数据·elasticsearch·jenkins