zoukankan      html  css  js  c++  java
  • 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 中通过 getsearch 请求取回部分字段,而不是整个文档。

    • 这样更容易排查错误,因为你可以准确的看到每个文档中包含的内容,而不是只能从一堆 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 参数来过滤你需要的字段。

  • 相关阅读:
    支持复制粘贴word公式的wangEditor编辑器
    支持复制粘贴word公式的KindEditor编辑器
    支持复制粘贴word公式的CKEditor编辑器
    支持复制粘贴word公式的百度HTML编辑器
    支持复制粘贴word公式的百度Web编辑器
    PHP 大文件上传分享(500M以上)
    PHP 大文件上传问题(500M以上)
    SAP ABAP报表依赖设计原理详解
    获得某个时间段内修改过的所有ABAP对象列表
    FLINK实例(13):Flink的重启策略(一)
  • 原文地址:https://www.cnblogs.com/bonelee/p/6428321.html
Copyright © 2011-2022 走看看