Update /Upsert with document AND script

Hi:
The problem I have is as follows:
Index may or may not have the document, If the document does not exist, index(INSERT) the document, Else,
Update the existing document using an INLINE script. (the script takes a value from the new document and adds it to the existing document)

However, the Update/Upsert API will not allow for me to have a script and a DOC at the same time. Can some one provide suggestions on how I might be able to achieve it ? (using the Java API) and ES 1.5.2 with Java 7

Thanks
Ramdev

Have a look at the upsert documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#upserts

You can specify the script together with the upsert option and this should achieve what you are looking for.

In the Java API you would be looking for the setUpsert() method on UpdateRequestBuilder