# Accessing parsed date values in Update by Query script

**URL:** <https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980>\
**Category:** Elasticsearch\
**Created:** [April 29, 2019, 6:44pm UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980 "2019-04-29T18:44:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Bolle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_bolle/32/52060_2.png) [@Jeff\_Bolle](https://discuss.elastic.co/u/Jeff_Bolle)\
**Post date:** [April 29, 2019, 6:44pm UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980/1 "2019-04-29T18:44:47Z")

</div>

Inside of the script context for an Update By Query, is there any way (other than parsing the raw strings), to access the doc values for date fields? I'm trying to write a script to handle some dates on some of our objects, and we have a number of different supported input formats, which are all handled by the field mapping on the index.

I would be happy to either access to doc value field as a string, or as an actual Object in Painless. I've tried `doc['field_name']`, but this returned as `"Variable [doc] is not defined."` I tried adding the `"docvalue_fields"` line in the update\_by\_query request, but it does not appear to help.

If the above is not possible, can someone point to a working `parseBest` example using a `DateTimeFormatter`? I see the call is supported, but my attempts to use it have failed. I used it similarly to how I would in Java:  
`TemporalAccessor temporalAccessor = dtf.parseBest(date, OffsetDateTime::from, LocalDateTime::from);`

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 7, 2019, 12:24am UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980/2 "2019-05-07T00:24:57Z")

</div>

Update scripts only have access to the source of the document being updated, so you will need to do parsing yourself in this case.

Regarding your issues with using `parseBest` failing, can you elaborate on the error you receive?

---

<div class="post-metadata">

**Author:** ![Jeff\_Bolle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_bolle/32/52060_2.png) [@Jeff\_Bolle](https://discuss.elastic.co/u/Jeff_Bolle)\
**Post date:** [May 7, 2019, 3:00am UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980/3 "2019-05-07T03:00:39Z")

</div>

I apologize, I don't have the error in front of me right now, but basically it didn't like the lambda references in the varargs.

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [May 7, 2019, 4:46pm UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980/4 "2019-05-07T16:46:09Z")

</div>

Hi Jeff\_Bolle,

Unfortunately, two compounding issues have occurred here. Currently, Painless doesn't support either varargs. To resolve this use an array in place of the varargs. However, method references cannot be stored as part of local variables, but there is another work around. If you create a method, you can return the result of a method reference and then create an array in place of the varargs argument.

Something similar to the following should work:

```auto
TemporalQuery getTemporalQuery(TemporalQuery tq) {
    return tq
}

... <other code> ...

TemporalAccessor temporalAccessor = dtf.parseBest(date, new TemporalQuery[] {getTemporalQuery(OffsetDateTime::from), getTemporalQuery(LocalDateTime::from)}));

... <other code> ...

```

Will this work around work for you for now?

--Jack

---

<div class="post-metadata">

**Author:** ![Jeff\_Bolle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_bolle/32/52060_2.png) [@Jeff\_Bolle](https://discuss.elastic.co/u/Jeff_Bolle)\
**Post date:** [May 7, 2019, 7:08pm UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980/5 "2019-05-07T19:08:39Z")

</div>

Jack,  
Thanks, that is working perfectly.

---

<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:** [June 4, 2019, 7:08pm UTC](https://discuss.elastic.co/t/accessing-parsed-date-values-in-update-by-query-script/178980/6 "2019-06-04T19:08:47Z")

</div>

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