# Rest High Level Client Partial Nested Update Script

**URL:** <https://discuss.elastic.co/t/rest-high-level-client-partial-nested-update-script/202688>\
**Category:** Elasticsearch\
**Created:** [October 8, 2019, 2:38pm UTC](https://discuss.elastic.co/t/rest-high-level-client-partial-nested-update-script/202688 "2019-10-08T14:38:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![111211](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111211/32/54366_2.png) [@111211](https://discuss.elastic.co/u/111211)\
**Post date:** [October 8, 2019, 2:38pm UTC](https://discuss.elastic.co/t/rest-high-level-client-partial-nested-update-script/202688/1 "2019-10-08T14:38:25Z")

</div>

I wanna send Script to ElasticSearch.

I want to do a partial update inside a nested array.

But It didn't work well...

Below is the script code I created. At least this works well in kibana.

```
{ 
"script": {
"source" : "def target = ctx._source.daily_schedules.findAll(it -> { for(i in params.json) { if(i.date == it.date) { for(j in i.entrySet()) { it[j.getKey()] = j.getValue() } return true;} } return false; }) ",
"params": {
  "json" : [{
    "date" : "2019-10-08",
    "isBusinessDay" : false,
    "isSaleDay" : false,
    "hourly_schedules": [
    {
      "dateTime" : "2019-10-08T00:30:00+09:00",
      "stock" : 2,
      "bookingCount" : 0,
      "remainStock" : 2
    },
    {
      "dateTime" : "2019-10-08T01:00:00+09:00",
      "stock" : 2,
      "bookingCount" : 0,
      "remainStock" : 2
    }
    ]
  },
  {
    "date" : "2019-10-09",
    "isBusinessDay" : false,
    "isSaleDay" : false,
    "hourly_schedules": [{
      "dateTime" : "2019-10-09T00:00:00+09:00",
      "stock": 998,
      "bookingCount" : 998,
      "remainStock" : 0
    },
    {
      "dateTime" : "2019-10-09T00:30:00+09:00",
      "stock" : 2,
      "bookingCount" : 0,
      "remainStock" : 2
    },
    {
      "dateTime" : "2019-10-09T01:00:00+09:00",
      "stock" : 2,
      "bookingCount" : 0,
      "remainStock" : 2
    }
    ]
  }
  ]
  }
 }
}

```

The result of the operation is as follows.

```
"daily_schedules": [
  {
    "date": "2019-10-08",
    "isBusinessDay": false,
    "isSaleDay": false,
    "hourly_schedules": [
      {
        "dateTime": "2019-10-08T00:30:00+09:00",
        "bookingCount": 0,
        "remainStock": 2,
        "stock": 2
      },
      {
        "dateTime": "2019-10-08T01:00:00+09:00",
        "bookingCount": 0,
        "remainStock": 2,
        "stock": 2
      }
    ]
  },
  {
    "date": "2019-10-09",
    "isBusinessDay": false,
    "isSaleDay": false,
    "hourly_schedules": [
      {
        "dateTime": "2019-10-09T00:00:00+09:00",
        "bookingCount": 998,
        "remainStock": 0,
        "stock": 998
      },
      {
        "dateTime": "2019-10-09T00:30:00+09:00",
        "bookingCount": 0,
        "remainStock": 2,
        "stock": 2
      },
      {
        "dateTime": "2019-10-09T01:00:00+09:00",
        "bookingCount": 0,
        "remainStock": 2,
        "stock": 2
      }
    ]
  }

```

I'm using REST HIGH LEVEL CLIENT on Spring Framework.

However, the above script does not work well here.

```
data class AvailableDailySchedule(
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
    val date: LocalDate,
    @get:JsonProperty("isBusinessDay") val isBusinessDay: Boolean,
    @get:JsonProperty("isSaleDay") val isSaleDay: Boolean,
    val hourly_schedules : List<AvailableHourlySchedule>
)

```

This is Class

```
    availableDailyScheduleList: List<AvailableDailySchedule>
    val parameters = mutableMapOf<String, Any>()
    parameters["json"] = availableDailyScheduleList

    val inline = Script(
        ScriptType.INLINE, "painless",
        "def target = ctx._source.daily_schedules.findAll(it -> { for(i in params.json) { if(i.date == it.date) { for(j in i.entrySet()) { it[j.getKey()] = j.getValue() } return true;} } return false; })",
        parameters
    )
    request.script(inline)

```

It is RestHighLevelClient Code.  
The above language is written in Kotlin.  
This code unfortunately doesn't work with the following error:

```
cannot write xcontent for unknown value of type class AvailableDailySchedule

```

So I tried changing my List to String using Jackson's Object Mapper as well, but still to no avail.

like this

```
    val parameters = mutableMapOf<String, Any>()
    parameters["json"] = ObjectMapper.writeValueAsString(availableDailyScheduleList)

```

However, this method still generates the following error:

```
cannot iterate over java.lang.string

```

Not all methods work.

Please Help me.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 5, 2019, 2:38pm UTC](https://discuss.elastic.co/t/rest-high-level-client-partial-nested-update-script/202688/2 "2019-11-05T14:38:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
