ES _source字段介绍——json文档,去掉的话无法更新部分文档,最重要的是无法reindex...

摘自:https://es.xiaoleilu.com/070_Index_Mgmt/31_Metadata_source.html

 

 

The _source field stores the JSON you send to Elasticsearch and you can choose to only return certain fields if needed, which is perfect for your use case. I have never heard that the stored fields will be faster for searches. The _source field could be bigger on disk space, but if you have to store every field there is no need to use stored fields over the _source field. If you do disable the source field it will mean:

  • You won’t be able to do partial updates
  • You won’t be able to re-index your data from the JSON in your Elasticsearch cluster, you’ll have to re-index from the data source (which is usually a lot slower).

 

元数据:_source 字段

默认情况下,Elasticsearch 用 JSON 字符串来表示文档主体保存在 _source 字段中。像其他保存的字段一样,_source 字段也会在写入硬盘前压缩。

这几乎始终是需要的功能,因为:

  • 搜索结果中能得到完整的文档 —— 不需要额外去别的数据源中查询文档

  • 如果缺少 _source 字段,部分 更新 请求不会起作用

  • 当你的映射有变化,而且你需要重新索引数据时,你可以直接在 Elasticsearch 中操作而不需要重新从别的数据源中取回数据。

  • 你可以从 _source 中通过 get 或 search 请求取回部分字段,而不是整个文档。

  • 这样更容易排查错误,因为你可以准确的看到每个文档中包含的内容,而不是只能从一堆 ID 中猜测他们的内容。

即便如此,存储 _source 字段还是要占用硬盘空间的。假如上面的理由对你来说不重要,你可以用下面的映射禁用 _source 字段:

PUT /my_index
{
    "mappings": {
        "my_type": {
            "_source": {
                "enabled":  false
            }
        }
    }
}

在搜索请求中你可以通过限定 _source 字段来请求指定字段:

GET /_search
{
    "query":   { "match_all": {}},
    "_source": [ "title", "created" ]
}

这些字段会从 _source 中提取出来,而不是返回整个 _source 字段。

储存字段

除了索引字段的值,你也可以选择 储存 字段的原始值以备日后取回。使用 Lucene 做后端的用户用储存字段来选择搜索结果的返回值,事实上,_source 字段就是一个储存字段。

在 Elasticsearch 中,单独设置储存字段不是一个好做法。完整的文档已经被保存在 _source 字段中。通常最好的办法会是使用 _source 参数来过滤你需要的字段。












本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com//p/6428321.html ,如需转载请自行联系原作者


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值