我有一个问题,我正在尝试更新ES中的对象,因此,每次查询它时,我都会获取所有更新的信息。我有一个像这样的对象:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 768,
"successful": 768,
"failed": 0
},
"hits": {
"total": 456,
"max_score": 1,
"hits": [
{
"_index": "sometype_1",
"_type": "sometype",
"_id": "12312321312312",
"_score": 1,
"_source": {
"readModel": {
"id": "asdfqwerzcxv",
"status": "active",
"hidden": false,
"message": "hello world",
},
"model": {
"id": "asdfqwerzcxv",
"content": {
"objectId": "421421312312",
"content": {
"@type": "text",
"text": "hello world"
}
..... //the rest of the object...
我想更新消息(读取模型的一部分),所以我做了这样的事情:
PUT test/readModel.id/ID123
{
"message" : "hello"
}
但是每次查询ID123时,我都会得到相同的信息(更糟糕的是,我制作的PUT越多,获得的对象也就越多(具有相同的信息)
有什么想法吗?
答案 0 :(得分:2)
如果只需要更新一个文档,则可以像这样使用Update API:
POST sometype_1/sometype/12312321312312/_update
{
"doc": {
"model.message": { ... your JSON object here... }
}
}
如果多个文档可以有readModel.id: asdfqwerzcxv
,并且您要使用相同的message
更新它们,那么您就需要像这样_ {p3
POST sometype_1/_update_by_query
{
"script": {
"source": "ctx._source.message = params.message",
"lang": "painless",
"params": {
"message": "hello"
}
},
"query": {
"match": {
"readModel.id": "asdfqwerzcxv"
}
}
}