# How to access the fields of arrays of Object in Pianless Script

**URL:** <https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453>\
**Category:** Elasticsearch\
**Created:** [February 19, 2018, 12:47pm UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453 "2018-02-19T12:47:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakhirajpoot18](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@rakhirajpoot18](https://discuss.elastic.co/u/rakhirajpoot18)\
**Post date:** [February 19, 2018, 12:47pm UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453/1 "2018-02-19T12:47:37Z")

</div>

I am using this script

double new\_offer\_price = doc['offer\_price'].value;  
boolean deal\_type\_check = true;  
if (doc.containsKey('flash\_deal\_es')) {  
for (int i = 0; i \< doc['flash\_deal\_es'].length; i++) {  
if (params.platform\_type\_id == 0) {  
deal\_type\_check = (doc['flash\_deal\_es'][i].fd\_deal\_type.value == params.platform\_type\_id) ? true : false;  
}  
if (deal\_type\_check) {  
if (((params.cur\_date - doc['flash\_deal\_es'][i].fd\_start\_dt.date.getMillis()) \> 0) && ((doc['flash\_deal\_es'][i].fd\_end\_dt.date.getMillis() - params.cur\_date) \> 0)) {  
new\_offer\_price = doc['flash\_deal\_es'][i].fd\_offer\_price.value;  
}  
}  
}  
}  
return new\_offer\_price;

its not working properly,,  
is there any syntactical mistake???

---

<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:** [February 19, 2018, 5:39pm UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453/2 "2018-02-19T17:39:25Z")

</div>

You'll need to be more specific than "it's not working properly". Do you get an exception from elasticsearch when using that script? Why is the json requestion you are making?

Also, please blockquote code/json using triple quotes (it makes it much easier to read), eg:

```auto
double new_offer_price = doc['offer_price'].value;
boolean deal_type_check = true;
...

```

---

<div class="post-metadata">

**Author:** ![rakhirajpoot18](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@rakhirajpoot18](https://discuss.elastic.co/u/rakhirajpoot18)\
**Post date:** [February 20, 2018, 10:56am UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453/3 "2018-02-20T10:56:48Z")

</div>

No, I am not getting Exception,

---

<div class="post-metadata">

**Author:** ![rakhirajpoot18](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@rakhirajpoot18](https://discuss.elastic.co/u/rakhirajpoot18)\
**Post date:** [February 20, 2018, 10:58am UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453/4 "2018-02-20T10:58:04Z")

</div>

"\_script": {  
"script": {  
"source": "double new\_offer\_price = doc['offer\_price'].value;boolean deal\_type\_check = true;if(doc.containsKey('flash\_deal\_es')){for(int i=0; i\< doc['flash\_deal\_es'].length; i++) {if(params.platform\_type\_id == 0){deal\_type\_check = (doc['flash\_deal\_es'][i].fd\_deal\_type.value == params.platform\_type\_id) ? true : false;}if(deal\_type\_check){if(((params.cur\_date - doc['flash\_deal\_es'][i].fd\_start\_dt.date.getMillis()) \> 0) && ((doc['flash\_deal\_es'][i].fd\_end\_dt.date.getMillis() - params.cur\_date) \> 0)){new\_offer\_price = doc['flash\_deal\_es'][i].fd\_offer\_price.value;}}}}return new\_offer\_price;",  
"lang": "painless",  
"params": {  
"cur\_date": 1519121635067,  
"platform\_type\_id": 0  
}  
},  
"type": "number",  
"order": "asc"  
}

Can we print the value of variable of script in elasticsearch log???  
Elasticsearch:6.1

---

<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:** [February 21, 2018, 10:00pm UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453/5 "2018-02-21T22:00:27Z")

</div>

There is no logging functionality in painless as that would be a big performance hit if done on a search request matching many documents. Instead, there is [Debug.explain()](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-scripting-painless-debugging.html).

Since there is no exception, can you be more specific about what you are expecting from this request and what behavior you actually see?

---

<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:** [March 21, 2018, 10:00pm UTC](https://discuss.elastic.co/t/how-to-access-the-fields-of-arrays-of-object-in-pianless-script/120453/6 "2018-03-21T22:00:28Z")

</div>

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