【问题标题】:elasticsearch update a source field without re-indexing entire documentelasticsearch 更新源字段而不重新索引整个文档
【发布时间】:2015-08-05 07:36:09
【问题描述】:

我有文档 {customerID: 111, name: bob, approved: yes}

“已批准”字段未编入索引。我有一个映射设置为“已批准”:{“type”:“string”,“index”:“no”}

所以只有字段“customerID”和“name”被索引。

如何在不重新索引整个文档的情况下仅更新 _source 中已批准的字段?我可以将部分文档传递给更新,例如 {approved: no}

这可能吗?

【问题讨论】:

    标签: elasticsearch lucene


    【解决方案1】:

    您正在寻找的是partial update。问题是这实际上会隐式执行 delete+put+index,但是您只需将这种忙碌留给 ES,不会浪费时间进行网络往返。可能 ES 会优化这样的查询(在未索引字段的情况下,但 AFAIK 它现在不这样做)

    POST so/t3/1
    {
      "name": "Bob",
      "id": 1,
      "approved": "no"
    }
    
    GET so/t3/_search
    
    POST so/t3/1/_update
    {
      "doc": {
        "approved": "yes"
      }
    }
    
    {
       "took": 2,
       "timed_out": false,
       "_shards": {
          "total": 5,
          "successful": 5,
          "failed": 0
       },
       "hits": {
          "total": 1,
          "max_score": 1,
          "hits": [
             {
                "_index": "so",
                "_type": "t3",
                "_id": "1",
                "_score": 1,
                "_source": {
                   "name": "Bob",
                   "id": 1,
                   "approved": "yes"
                }
             }
          ]
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 2019-01-23
      相关资源
      最近更新 更多