elasticsearch不会更新文档

时间:2016-12-16 13:49:37

标签: elasticsearch

我正面临与文档更新相关的麻烦。

我能够索引(创建)文档并在索引上正确添加它们。

然而,当我尝试更新其中一个时,没有进行操作,文档没有更新。

当我第一次添加文档时,它就像:

{
        "user" : "user4",
        "timestamp" : "2016-12-16T15:00:22.645Z",
        "startTimestamp" : "2016-12-16T15:00:22.645Z",
        "dueTimestamp" : null,
        "closingTimestamp" : null,
        "matter" : "F1",
        "comment" : null,
        "status" : 0,
        "backlogStatus" : 20,
        "metainfos" : {
          "ceeaceaaaceeaceaaaceeaceaaaceeaaceaaaceeabceaaa" : [ "FZ11" ]
        },
        "resources" : [ ],
        "notes" : null
      }

这是我用来构建UpdateRequest的代码:

this.elasticsearchResources.getElasticsearchClient()
 .prepareUpdate()
 .setIndex(this.user.getMe().getUser())
 .setType(type)
 .setId(id.toString())
 .setDoc(source)
 .setUpsert(source)
 .setDetectNoop(true);

我还能够调试此请求的内容是否将其发送到elasticsearch。该文件是:

{
   "user":"user4",
   "timestamp":"2016-12-16T15:00:22.645Z",
   "startTimestamp":"2016-12-16T15:00:22.645Z",
   "dueTimestamp":null,
   "closingTimestamp":null,
   "matter":"F1",
   "comment":null,
   "status":0,
   "backlogStatus":20,
   "metainfos":{

   },
   "resources":[

   ],
   "notes":null
}

正如您所看到的,当我尝试更新文档时,唯一的区别是metainfos为空。

执行此update request后,文档未更新。我的意思是metainfos的内容与以前一样:

#curl -XGET 'http://localhost:9200/user4/fuas/_search?pretty'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "living_v1",
      "_type" : "fuas",
      "_id" : "327c9435-c394-11e6-aa90-02420a011808",
      "_score" : 1.0,
      "_routing" : "user4",
      "_source" : {
        "user" : "user4",
        "timestamp" : "2016-12-16T15:00:22.645Z",
        "startTimestamp" : "2016-12-16T15:00:22.645Z",
        "dueTimestamp" : null,
        "closingTimestamp" : null,
        "matter" : "F1",
        "comment" : null,
        "status" : 0,
        "backlogStatus" : 20,
        "metainfos" : {
>>>>>>>>    "ceeaceaaaceeaceaaaceeaceaaaceeaaceaaaceeabceaaa" : [ "FZ11" ]
        },
        "resources" : [ ],
        "notes" : null
      }
    } ]
  }
}

我不太清楚什么是错的。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

ElasticSearch不会更新空对象。您可以尝试:
null onChange
"metainfos":null

清理田地。