【问题标题】:Elasticseach - force a field to index only, avoid storeElasticsearch - 强制字段仅索引,避免存储
【发布时间】:2020-07-20 09:17:53
【问题描述】:

如何强制仅对字段进行索引而不存储数据。此选项在 Solr 中可用,但不确定在 Elasticseach 中是否可行。

【问题讨论】:

    标签: elasticsearch indexing


    【解决方案1】:

    来自document

    默认情况下,对字段值进行索引以使其可搜索,但它们 不存储。这意味着可以查询该字段,但 无法检索原始字段值。 通常这无关紧要。字段值已经是 _source 字段,默认存储。如果您只想检索单个字段或几个字段的值,而不是 整个_source,那么这可以通过源过滤来实现

    如果您不希望字段也存储在 _source 中。您可以在映射中从源中排除该字段

    映射:

    {
      "mappings": {
        "properties": {
          "title":{
            "type":"text"
          },
          "description":{
            "type":
          }
        }, 
        "_source": {
          "excludes": [
            "description"
          ]
        }
      }
    }
    

    查询:

    GET logs/_search
    {
      "query": {
        "match": {
          "description": "b" --> field description is searchable(indexed)
        }
      }
    }
    

    结果:

    "hits" : [
          {
            "_index" : "logs",
            "_type" : "_doc",
            "_id" : "-aC9V3EBkD38P4LIYrdY",
            "_score" : 0.2876821,
            "_source" : {
              "title" : "a" --> field "description" is not returned
            }
          }
        ]
    

    注意:

    从源中删除字段将导致以下问题

    1. update、update_by_query 和 reindex API。

    2. 动态突出显示。

    3. 能够从一个 Elasticsearch 索引重新索引到另一个,以更改映射或分析,或将索引升级到新的主要版本。

    4. 能够通过查看索引时使用的原始文档来调试查询或聚合。

    5. 将来可能会自动修复索引损坏。

    【讨论】:

      猜你喜欢
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多