# Upserting field doesn't work with elasticsearch-php

**URL:** https://discuss.elastic.co/t/upserting-field-doesnt-work-with-elasticsearch-php/118146
**Category:** Elasticsearch
**Created:** [February 2, 2018, 3:09am UTC](https://discuss.elastic.co/t/upserting-field-doesnt-work-with-elasticsearch-php/118146 "2018-02-02T03:09:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cloudsthere](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@cloudsthere](https://discuss.elastic.co/u/cloudsthere)
#### Post date: [February 2, 2018, 3:09am UTC](https://discuss.elastic.co/t/upserting-field-doesnt-work-with-elasticsearch-php/118146/1 "2018-02-02T03:09:29Z")

</div>

sentence in elasticsearch-php 6.0:

This means an upsert will attempt to run your update script, but if the document does not exist (or the field you are trying to update doesn’t exist), default values will be inserted instead.

when i try to upsert a field to existing document, it doesn't work and return a `null_pointer_exception`. Attempt with curl returns the same result.

Elasticsearch Reference [6.1] doesn't mention that upserting a field is available. maybe there is a version problem. There is no Elasticsearch-PHP [6.1] !!

Example from The Reference:

```auto
curl -XPOST 'localhost:9200/test/type1/1/_update?pretty' -H 'Content-Type: application/json' -d'
{
    "script" : {
        "source": "ctx._source.ava += params.count",
        "lang": "painless",
        "params" : {
            "count" : 4
        }
    },
    "upsert" : {
        "ava" : 1
    }
}
'

```

Doesn't work when the document exists and field 'ava' absents.

So, the problem is how to upsert a field to an existing document? curl example is ok, thanks.

---

<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 2, 2018, 3:09am UTC](https://discuss.elastic.co/t/upserting-field-doesnt-work-with-elasticsearch-php/118146/2 "2018-03-02T03:09:33Z")

</div>

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