elasticsearch更新源字段而不重新索引整个文档

时间:2015-08-05 07:36:10

标签: elasticsearch lucene

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

该领域"已批准"没有编入索引。我有一个映射集"已批准":{" type" :" string"," index" :"不" }

所以只有字段" customerID"和"名称"被编入索引。

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

这可能吗?

1 个答案:

答案 0 :(得分: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"
            }
         }
      ]
   }
}