代码之家  ›  专栏  ›  技术社区  ›  Stpete111

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

  •  0
  • Stpete111  · 技术社区  · 7 年前

    我在我们的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 回复  |  直到 7 年前
        1
  •  1
  •   Stpete111    7 年前

    我已经通过文件搞清楚了:

    呼叫URL是:

    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"
                }
            ] }
    }
    

    希望这对将来的人有帮助。