1. _source field

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-source-field.html

译文链接 : http://www.apache.wiki/display/Elasticsearch/_source+field

贡献者 : 朱彦安ApacheCNApache中文网

_source字段包含在索引时传递的原始 JSON 文档正文。该 _source 字段本身不被索引(因此是不可搜索的),但它被存储,以便在执行撷取请求时可以返回,例如 get search

1.1.1. 禁用_source字段

虽然很方便,但是 _source 字段确实在索引中有不小的存储开销。 因此,可以使用如下方式禁用 :

curl -XPUT 'localhost:9200/tweets?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "tweet": {
      "_source": {
        "enabled": false
      }
    }
  }
}
'

警告 :

1.1.2. 在禁用_source 字段之前请考虑

用户经常禁用 _source 字段而不考虑后果,然后为此后悔。 如果 _source 字段不可用,则不支持许多功能 :

  • updateupdate_by_queryreindex APIs.
  • 高亮
  • 将索引从一 个Elasticsearch 索引 reindex(重索引)到另一个索引的能力,以更改映射或分析,或将索引升级到新的主要版本。
  • 通过查看索引时使用的原始文档来调试查询或聚合的能力。
  • 潜在的未来可能会自动修复索引损坏的能力。

提示

如果磁盘空间是瓶颈,应是增加压缩级别而不是禁用 _source

1.1.3. The metrics use case

指标用例与其他基于时间或日志记录的用例不同,因为有许多小型文档只包含数字,日期或关键字。

没有更新,没有高亮的请求,并且数据快速老化,因此不需要 reindex

搜索请求通常使用简单查询来按日期或标签过滤数据集,结果作为聚合返回。

在这种情况下,禁用 _source 字段将节省空间并减少 I/O

建议在 metrics case 下禁用 _all 字段。

1.1.4. 包含 / 排除 _source 中的字段

专家级功能是在文档索引后但在 _source 字段存储之前修剪 _source 字段的内容。

警告

_source 中删除字段与禁用 _source 有类似的缺点,尤其是您不能将文档从一个 Elasticsearch 索引重新索引到另一个。

考虑使用 source filtering(源代码)过滤。

可以使用 includes / excludes 参数(也可以接受通配符),如下所示 :

curl -XPUT 'localhost:9200/logs?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "event": {
      "_source": {
        "includes": [
          "*.count",
          "meta.*"
        ],
        "excludes": [
          "meta.description",
          "meta.other.*"
        ]
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/logs/event/1?pretty' -H 'Content-Type: application/json' -d'
{
  "requests": {
    "count": 10,
    "foo": "bar" # 1
  },
  "meta": {
    "name": "Some metric",
    "description": "Some metric description", # 2
    "other": {
      "foo": "one", # 3
      "baz": "two" # 4
    }
  }
}
'
curl -XGET 'localhost:9200/logs/event/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "meta.other.foo": "one" # 5
    }
  }
}
'

| 1234 | 这些字段将从存储的 _source 字段中删除。 | | 5 | 我们仍然可以搜索这个字段,即使它不在存储的 _source。 |

Copyright © Kilvn 2021. all right reserved,powered by Gitbook最后更新时间: 2021-06-08 20:22:42

results matching ""

    No results matching ""