ElasticSearch-如何在文档数组中编辑字段

时间:2018-11-14 17:58:29

标签: elasticsearch

我在ElasticSearch索引中有一个文档,如下所示:

{
 "_index": "nm_doc",
                "_type": "nm_doc",
                "_id": "JRPXqmQBatyecf67YEfq",
                "_score": 0.86147696,
                "_source": {
                    "text": "A 29-year-old IT professional from Bhopal was convicted and sentenced to life imprisonment by an Additional Sessions Court in Pune on Wednesday for the rape and brutal murder of a woman in 2008, after she had refused his advances. Watch What Else is Making News The court found Manu Mohinder Ebrol, who worked in the same firm as the girl, of raping and killing the woman after stabbing her 18 times on the night of October 20, 2008, in her rented apartment. After committing the crime, Ebrol had fled to Bhopal. He was arrested later by Pune Police. The prosecution examined 26 witnesses for the case and forensic evidence such as call details and medical records also proved crucial. For all the latest Pune News , download Indian Express App",
                    "entities": [
                        {
                            "name": "Mohinder Ebrol"
                        },
                        {
                            "name": "Sessions Court"
                        },
                        {
                            "name": "Pune Police"
                        },
                        {
                            "name": "Pune News"
                        },
                        {
                            "name": "Indian Express"
                        }
                    ]
}

如果我只想将该数组(Mohinder Ebrol)中的名字编辑为Manu Ebrol,我将如何通过API调用来实现?我需要传递整个数组来更新一个名称吗?

1 个答案:

答案 0 :(得分:1)

我已经通过文档找到了答案

通话网址是:

POST http://elastichost:9200/indexname/_doc/JRPXqmQBatyecf67YEfq/_update?pretty

主体看起来像这样(是的,您必须提供整个数组):

{
  "doc": { "entities": [
            {
                "name": "Manu Ebrol"
            },
            {
                "name": "Sessions Court"
            },
            {
                "name": "Pune Police"
            },
            {
                "name": "Pune News"
            },
            {
                "name": "Indian Express"
            }
        ] }
}

希望这对以后的人有帮助。