# Scripting (Javascript) method list

**URL:** <https://discuss.elastic.co/t/scripting-javascript-method-list/40385>\
**Category:** Elasticsearch\
**Created:** [January 28, 2016, 3:58pm UTC](https://discuss.elastic.co/t/scripting-javascript-method-list/40385 "2016-01-28T15:58:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![havran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/havran/32/5726_2.png) [@havran](https://discuss.elastic.co/u/havran)\
**Post date:** [January 28, 2016, 3:58pm UTC](https://discuss.elastic.co/t/scripting-javascript-method-list/40385/1 "2016-01-28T15:58:23Z")

</div>

Hi. I'm trying hard find more information about scripting in Elasticsearch but i found no information about method like add method (like piece of code here).

ctx.\_source.myNestedArrayField.add({..new object..});

I realize make update script with try/error method and found some useful info in comments but i find no comapct information about this topic.

Please is there any source/sources about this topic?

Thanks.

For curiosity my script (in lang javascript) for add new/update existing object on nested field.

```javascript
    var logger = org.elasticsearch.common.logging.ESLoggerFactory.getLogger('JS-UPDATE-INDEX');

    ids = {};
    for (var i = 0; i < post_customers.length; i++) {
      ids[post_customers[i].classification_id] = i;
    }

    if (ctx._source.post_customers != null) {
      for (var j = 0; j < ctx._source.post_customers.length; j++) {
        if (!(ctx._source.post_customers[j].classification_id in ids)) continue;

        pos = ids[ctx._source.post_customers[j].classification_id];
        delete(ids[ctx._source.post_customers[j].classification_id]);

        logger.info('Update nested object POST_ID: ' + ctx._id + ' CLASSIFICATION_ID: ' + ctx._source.post_customers[j].classification_id);
        ctx._source.post_customers[j] = post_customers[pos];
      }
    }

    if (Object.keys(ids).length > 0) {
      logger.info('Insert nested object POST_ID: ' + ctx._id + ' CLASSIFICATION_IDS: ' + Object.keys(ids).join(','));
      for (id in ids) {
        if (ctx._source.post_customers == null) {
          logger.info('Empty: inserting ' + ids[id]);
          ctx._source.post_customers = [post_customers[ids[id]]];
        }
        else {
          logger.info('NotEmpty: inserting ' + ids[id]);
          ctx._source.post_customers.add(post_customers[ids[id]]);
        }
      }
    }

```

Thanks again.

---

<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:** [July 5, 2017, 11:20pm UTC](https://discuss.elastic.co/t/scripting-javascript-method-list/40385/2 "2017-07-05T23:20:43Z")

</div>


