Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java api更新elasticsearch中的嵌套字段值_Java_Scala_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Updates_Scala 2.11 - Fatal编程技术网 elasticsearch,updates,scala-2.11,Java,Scala,elasticsearch,Updates,Scala 2.11" /> elasticsearch,updates,scala-2.11,Java,Scala,elasticsearch,Updates,Scala 2.11" />

如何使用java api更新elasticsearch中的嵌套字段值

如何使用java api更新elasticsearch中的嵌套字段值,java,scala,elasticsearch,updates,scala-2.11,Java,Scala,elasticsearch,Updates,Scala 2.11,我在elasticsearch中有以下文档 { "uuid":"123", "Email":"mail@example.com", "FirstName":"personFirstNmae", "LastName":"personLastName", "Inbox":{ "uuid":"1234", "messageList":[ { "uuid":"321", "Subject":"subject1", "Body":"bodyText1", "ArtworkU

我在elasticsearch中有以下文档

{
"uuid":"123",
"Email":"mail@example.com",
"FirstName":"personFirstNmae",
"LastName":"personLastName",
"Inbox":{
"uuid":"1234",
"messageList":[
{
    "uuid":"321",
    "Subject":"subject1",
    "Body":"bodyText1",
    "ArtworkUuid":"101",
    "DateAndTime":"2015-10-15T10:59:12.096+05:00",
    "ReadStatusInt":0,
    "Delete":{
        "deleteStatus":0,
        "deleteReason":0
             }
},
{
    "uuid":"123",
    "Subject":"subject",
    "Body":"bodyText",
    "ArtworkUuid":"100",
    "DateAndTime":"2015-10-15T10:59:11.982+05:00",
    "ReadStatusInt":1,
    "Delete":{
        "deleteStatus":0,
        "deleteReason":0
          }
}
              ]
        }
}
这是文档的映射

 {
  "testdb" : {
    "mappings" : {
      "directUser" : {
        "properties" : {
          "Email" : {
            "type" : "string",
            "store" : true
          },
          "FirstName" : {
            "type" : "string",
            "store" : true
          },
          "Inbox" : {
            "type" : "nested",
            "include_in_parent" : true,
            "properties" : {
              "messageList" : {
                "type" : "nested",
                "include_in_parent" : true,
                "properties" : {
                  "ArtworkUuid" : {
                    "type" : "string",
                    "store" : true
                  },
                  "Body" : {
                    "type" : "string",
                    "store" : true
                  },
                  "DateAndTime" : {
                    "type" : "date",
                    "store" : true,
                    "format" : "dateOptionalTime"
                  },
                  "Delete" : {
                    "type" : "nested",
                    "include_in_parent" : true,
                    "properties" : {
                      "deleteReason" : {
                        "type" : "integer",
                        "store" : true
                      },
                      "deleteStatus" : {
                        "type" : "integer",
                        "store" : true
                      }
                    }
                  },
                  "ReadStatusInt" : {
                    "type" : "integer",
                    "store" : true
                  },
                  "Subject" : {
                    "type" : "string",
                    "store" : true
                  },
                  "uuid" : {
                    "type" : "string",
                    "store" : true
                  }
                }
              },
              "uuid" : {
                "type" : "string",
                "store" : true
              }
            }
          },

          "LastName" : {
            "type" : "string",
            "store" : true
          },
                    "uuid" : {
            "type" : "string",
            "store" : true
          }
        }
      }
    }
  }
}
现在我想将uuid为321(
Inbox.messageList.uuid
)的文档的
Inbox.messageList.Delete.deleteStatus
Inbox.messageList.Delete.deleteReason
的值从0更新为1。 我想实现这样的目标

{
"uuid":"123",
"Email":"mail@example.com",
"FirstName":"personFirstNmae",
"LastName":"personLastName",
"Inbox":{
"uuid":"1234",
"messageList":[
{
    "uuid":"321",
    "Subject":"subject1",
    "Body":"bodyText1",
    "ArtworkUuid":"101",
    "DateAndTime":"2015-10-15T10:59:12.096+05:00",
    "ReadStatusInt":0,
    "Delete":{
        "deleteStatus":1,
        "deleteReason":1
             }
},
{
    "uuid":"123",
    "Subject":"subject",
    "Body":"bodyText",
    "ArtworkUuid":"100",
    "DateAndTime":"2015-10-15T10:59:11.982+05:00",
    "ReadStatusInt":1,
    "Delete":{
        "deleteStatus":0,
        "deleteReason":0
          }
}
              ]
        }
}
我正在尝试以下代码来实现我想要的更新文档

 var xb:XContentBuilder=XContentFactory.jsonBuilder().startObject()
                             .startObject("Inbox")
                            xb.startArray("messageList") 
                                xb.startObject();
                                    xb.startObject("Delete")
                                      xb.field("deleteStatus",1)
                                      xb.field("deleteReason",1)
                                    xb.endObject()
                                  xb.endObject();      

                              xb.endArray()
                           .endObject()
                          xb.endObject()

           val responseUpdate=client.prepareUpdate("testdb", "directUser", directUserObj.getUuid.toString())
         .setDoc(xb).execute().actionGet()
但是从这个代码中,我的医生变成了

{"uuid":"123",
"Email":"mail@example.com",
"FirstName":"personFirstNmae",
"LastName":"personLastName",
,"Inbox":{
"uuid":"1234",
"messageList":[
   {
"Delete":{
"deleteStatus":1,
"deleteReason":1
}
   }
          ]
          }
}

我不想这样,请帮助我如何实现我想要的文档,Iam使用elasticsearch版本1.6

我发现更新单个嵌套字段的最佳方法是使用elasticsearch更新API,该API采用(参数化)脚本。上次我检查时,这种东西只在groovy脚本中受支持,而在lucene表达式脚本中不受支持(不幸的是)。更新产生结果的原因是更新的是整个嵌套对象,而不是特定的嵌套项。Groovy脚本更新将允许您选择并更新具有指定ID的嵌套对象。

您还可以查看我当前更新的嵌套对象以及我如何在Java中使用UpdateRequest类

特别是对于JAVA API,还可以使用PeteyPabPro更新嵌套文档。

的可能副本