12

如何向 Elasticsearch 索引中的现有文档添加其他属性。

$ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}'

这将在索引中创建一个文档。如何向文档添加属性?认为

"new_attribute":"new_value"

这会将文档修改为

"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
"new_attribute" :"new_value"
4

2 回答 2

9

我认为更新 api 是可能的。检查这个:

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_update_part_of_a_document

并向下滚动以“向文档添加新字段”。

问候

于 2013-08-27T15:59:15.070 回答
7

我知道这是一个旧帖子,但我认为它很方便

POST /twitter/tweet/1/_update
{
  "doc": {
    "new_attribute":""
  }
}
于 2015-03-27T14:45:02.100 回答