# NPE with Upsert Java API

**URL:** <https://discuss.elastic.co/t/npe-with-upsert-java-api/10224>\
**Category:** Elasticsearch\
**Created:** [January 3, 2013, 11:31pm UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224 "2013-01-03T23:31:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TeeTim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/teetim/32/2370_2.png) [@TeeTim](https://discuss.elastic.co/u/TeeTim)\
**Post date:** [January 3, 2013, 11:31pm UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/1 "2013-01-03T23:31:56Z")

</div>

Trying to utilize the Upsert Java API without success. ES is running local  
standalone instance; connecting, indexing, and querying without problems.  
I'm using the UpdateRequestBuilder to prep the request and have tried the  
various forms of the setUpsert() API: setUpsert(XContentBuilder),  
setUpsert(Map source), setUpsert(IndexRequest). All result in a  
NullPointerException when execute() is called.

Here's the code:

try  
{  
NodeContent content = NodeContent.forJson();  
XContentBuilder builder = content.on( source ).adapt( adapter );

```
// build the request
IndexRequest indexRequest = client
        .prepareIndex( indexName, indexType )
        .setSource( builder )
        .request();

UpdateResponse response = client.prepareUpdate()
        .setIndex( indexName )
        .setType( indexType )
        .setUpsert( indexRequest )
        .execute()
        .actionGet();

LOG.debug( String.format( "upserted content : %s : %s", 

```

response.getId(), t ) );

```
return NodeResult.minimal( response );

```

}  
catch( Exception uhoh )  
{  
throw new NodeException( String.format( "failed to upsert content : %s  
: %s : %s", indexName, indexType, source.getId() ), uhoh );  
}

Here's the stacktrace:

2013-01-03 18:19:57,863 ERROR (main) datastore.ElementDataStoreImpl\<135\>:  
failed to save element : [server2.lab.netuitive.com](http://server2.lab.netuitive.com)  
com.netuitive.collector.agent.node.NodeException: failed to upsert content  
: elements : element : null; nested exception is  
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
Failed execution  
at  
com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:627)  
at  
com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElement(ElementDataStoreImpl.java:129)  
at  
com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElements(ElementDataStoreImpl.java:149)  
at  
com.netuitive.collector.element.datastore.ElementDataStoreTests.checkSaveElements(ElementDataStoreTests.java:66)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
at java.lang.reflect.Method.invoke(Method.java:597)  
at  
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)  
at  
org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)  
at  
org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
at java.lang.reflect.Method.invoke(Method.java:597)  
at  
org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)  
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)  
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)  
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)  
at  
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)  
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)  
at org.testng.TestRunner.privateRun(TestRunner.java:767)  
at org.testng.TestRunner.run(TestRunner.java:617)  
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)  
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)  
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)  
at org.testng.SuiteRunner.run(SuiteRunner.java:240)  
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)  
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)  
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)  
at org.testng.TestNG.run(TestNG.java:1036)  
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)  
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)  
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)  
Caused by:  
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
Failed execution  
at  
org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)  
at  
org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)  
at  
com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:619)  
... 34 more  
Caused by: java.lang.NullPointerException  
at  
org.elasticsearch.common.io.stream.HandlesStreamOutput.writeString(HandlesStreamOutput.java:82)  
at  
org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:548)  
at  
org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:540)  
at  
org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:184)  
at  
org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:63)  
at  
org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:109)  
at  
org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:211)  
at  
org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)  
at  
org.elasticsearch.client.support.AbstractClient.update(AbstractClient.java:105)  
at  
org.elasticsearch.client.transport.TransportClient.update(TransportClient.java:318)  
at  
org.elasticsearch.action.update.UpdateRequestBuilder.doExecute(UpdateRequestBuilder.java:298)  
at  
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
at  
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
at  
com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:618)  
... 34 more

Am I using this API correctly? What am I missing? Any suggestions would be  
greatly appreciated.

Thanks  
Tim

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 4, 2013, 1:18am UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/2 "2013-01-04T01:18:21Z")

</div>

The NullPointerException is thrown because of a bug in the Update request  
serialization. The bug is triggered because your request doesn't contain id  
of the document that you want to update, and a script or a document that  
that you want to update your existing document with:

```
    UpdateResponse response = client.prepareUpdate()

```

- 

```
           .setId("some id here")*

```

- 

```
           .setDoc("{ some fields here}")*
          .setIndex( indexName )
          ....

```

On Thursday, January 3, 2013 6:31:56 PM UTC-5, Tim Sheridan wrote:

> Trying to utilize the Upsert Java API without success. ES is running local  
> standalone instance; connecting, indexing, and querying without problems.  
> I'm using the UpdateRequestBuilder to prep the request and have tried the  
> various forms of the setUpsert() API: setUpsert(XContentBuilder),  
> setUpsert(Map source), setUpsert(IndexRequest). All result in a  
> NullPointerException when execute() is called.
> 
> Here's the code:
> 
> try  
> {  
> NodeContent content = NodeContent.forJson();  
> XContentBuilder builder = content.on( source ).adapt( adapter );
> 
> ```
> // build the request
> IndexRequest indexRequest = client
> .prepareIndex( indexName, indexType )
> .setSource( builder )
> .request();
> 
> UpdateResponse response = client.prepareUpdate()
> .setIndex( indexName )
> .setType( indexType )
> .setUpsert( indexRequest )
> .execute()
> .actionGet();
> 
> LOG.debug( String.format( "upserted content : %s : %s", 
> 
> ```
> 
> response.getId(), t ) );
> 
> ```
> return NodeResult.minimal( response );
> 
> ```
> 
> }  
> catch( Exception uhoh )  
> {  
> throw new NodeException( String.format( "failed to upsert content : %s  
> : %s : %s", indexName, indexType, source.getId() ), uhoh );  
> }
> 
> Here's the stacktrace:
> 
> 2013-01-03 18:19:57,863 ERROR (main) datastore.ElementDataStoreImpl\<135\>:  
> failed to save element : [server2.lab.netuitive.com](http://server2.lab.netuitive.com)  
> com.netuitive.collector.agent.node.NodeException: failed to upsert content  
> : elements : element : null; nested exception is  
> org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> Failed execution  
> at  
> com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:627)  
> at  
> com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElement(ElementDataStoreImpl.java:129)  
> at  
> com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElements(ElementDataStoreImpl.java:149)  
> at  
> com.netuitive.collector.element.datastore.ElementDataStoreTests.checkSaveElements(ElementDataStoreTests.java:66)  
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> at  
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> at  
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> at java.lang.reflect.Method.invoke(Method.java:597)  
> at  
> org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)  
> at  
> org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)  
> at  
> org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)  
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> at  
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> at  
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> at java.lang.reflect.Method.invoke(Method.java:597)  
> at  
> org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)  
> at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)  
> at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)  
> at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)  
> at  
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)  
> at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)  
> at org.testng.TestRunner.privateRun(TestRunner.java:767)  
> at org.testng.TestRunner.run(TestRunner.java:617)  
> at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)  
> at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)  
> at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)  
> at org.testng.SuiteRunner.run(SuiteRunner.java:240)  
> at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  
> at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)  
> at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)  
> at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)  
> at org.testng.TestNG.run(TestNG.java:1036)  
> at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)  
> at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)  
> at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)  
> Caused by:  
> org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> Failed execution  
> at  
> org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)  
> at  
> org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)  
> at  
> com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:619)  
> ... 34 more  
> Caused by: java.lang.NullPointerException  
> at  
> org.elasticsearch.common.io.stream.HandlesStreamOutput.writeString(HandlesStreamOutput.java:82)  
> at  
> org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:548)  
> at  
> org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:540)  
> at  
> org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:184)  
> at  
> org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:63)  
> at  
> org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:109)  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:211)  
> at  
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)  
> at  
> org.elasticsearch.client.support.AbstractClient.update(AbstractClient.java:105)  
> at  
> org.elasticsearch.client.transport.TransportClient.update(TransportClient.java:318)  
> at  
> org.elasticsearch.action.update.UpdateRequestBuilder.doExecute(UpdateRequestBuilder.java:298)  
> at  
> org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
> at  
> org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
> at  
> com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:618)  
> ... 34 more
> 
> Am I using this API correctly? What am I missing? Any suggestions would be  
> greatly appreciated.
> 
> Thanks  
> Tim

--

---

<div class="post-metadata">

**Author:** ![avin](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@avin](https://discuss.elastic.co/u/avin)\
**Post date:** [January 5, 2013, 8:09pm UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/3 "2013-01-05T20:09:31Z")

</div>

I ran into the same issue and finally got it figured.

// This converts a Map

XContentBuilder b = SearchUtils._getDoc_(map);

UpdateRequestBuilder up = elasticClient.prepareUpdate(getIndexName(),  
getIndexType(), id).

```
    setConsistencyLevel(WriteConsistencyLevel.*DEFAULT*)

    .setDoc(b)

    .setUpsert(b);

```

On Thursday, January 3, 2013 3:31:56 PM UTC-8, Tim Sheridan wrote:

> Trying to utilize the Upsert Java API without success. ES is running local  
> standalone instance; connecting, indexing, and querying without problems.  
> I'm using the UpdateRequestBuilder to prep the request and have tried the  
> various forms of the setUpsert() API: setUpsert(XContentBuilder),  
> setUpsert(Map source), setUpsert(IndexRequest). All result in a  
> NullPointerException when execute() is called.
> 
> Here's the code:
> 
> try  
> {  
> NodeContent content = NodeContent.forJson();  
> XContentBuilder builder = content.on( source ).adapt( adapter );
> 
> ```
> // build the request
> IndexRequest indexRequest = client
> .prepareIndex( indexName, indexType )
> .setSource( builder )
> .request();
> 
> UpdateResponse response = client.prepareUpdate()
> .setIndex( indexName )
> .setType( indexType )
> .setUpsert( indexRequest )
> .execute()
> .actionGet();
> 
> LOG.debug( String.format( "upserted content : %s : %s", 
> 
> ```
> 
> response.getId(), t ) );
> 
> ```
> return NodeResult.minimal( response );
> 
> ```
> 
> }  
> catch( Exception uhoh )  
> {  
> throw new NodeException( String.format( "failed to upsert content : %s  
> : %s : %s", indexName, indexType, source.getId() ), uhoh );  
> }
> 
> Here's the stacktrace:
> 
> 2013-01-03 18:19:57,863 ERROR (main) datastore.ElementDataStoreImpl\<135\>:  
> failed to save element : [server2.lab.netuitive.com](http://server2.lab.netuitive.com)  
> com.netuitive.collector.agent.node.NodeException: failed to upsert content  
> : elements : element : null; nested exception is  
> org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> Failed execution  
> at  
> com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:627)  
> at  
> com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElement(ElementDataStoreImpl.java:129)  
> at  
> com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElements(ElementDataStoreImpl.java:149)  
> at  
> com.netuitive.collector.element.datastore.ElementDataStoreTests.checkSaveElements(ElementDataStoreTests.java:66)  
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> at  
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> at  
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> at java.lang.reflect.Method.invoke(Method.java:597)  
> at  
> org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)  
> at  
> org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)  
> at  
> org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)  
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> at  
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> at  
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> at java.lang.reflect.Method.invoke(Method.java:597)  
> at  
> org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)  
> at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)  
> at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)  
> at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)  
> at  
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)  
> at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)  
> at org.testng.TestRunner.privateRun(TestRunner.java:767)  
> at org.testng.TestRunner.run(TestRunner.java:617)  
> at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)  
> at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)  
> at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)  
> at org.testng.SuiteRunner.run(SuiteRunner.java:240)  
> at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  
> at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)  
> at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)  
> at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)  
> at org.testng.TestNG.run(TestNG.java:1036)  
> at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)  
> at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)  
> at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)  
> Caused by:  
> org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> Failed execution  
> at  
> org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)  
> at  
> org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)  
> at  
> com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:619)  
> ... 34 more  
> Caused by: java.lang.NullPointerException  
> at  
> org.elasticsearch.common.io.stream.HandlesStreamOutput.writeString(HandlesStreamOutput.java:82)  
> at  
> org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:548)  
> at  
> org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:540)  
> at  
> org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:184)  
> at  
> org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:63)  
> at  
> org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:109)  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:211)  
> at  
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)  
> at  
> org.elasticsearch.client.support.AbstractClient.update(AbstractClient.java:105)  
> at  
> org.elasticsearch.client.transport.TransportClient.update(TransportClient.java:318)  
> at  
> org.elasticsearch.action.update.UpdateRequestBuilder.doExecute(UpdateRequestBuilder.java:298)  
> at  
> org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
> at  
> org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
> at  
> com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:618)  
> ... 34 more
> 
> Am I using this API correctly? What am I missing? Any suggestions would be  
> greatly appreciated.
> 
> Thanks  
> Tim

--

---

<div class="post-metadata">

**Author:** ![TeeTim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/teetim/32/2370_2.png) [@TeeTim](https://discuss.elastic.co/u/TeeTim)\
**Post date:** [January 5, 2013, 8:44pm UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/4 "2013-01-05T20:44:40Z")

</div>

Cool. Your example provides an id when you prepare the update request. The  
doc for the Upsert feature states it will create the document with the  
provided if it doesn't already exists:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

In that case, does this mean the id will be generated for you? If so, does  
that mean the id an optional parameter on the call?

Thanks  
Tim

On Saturday, January 5, 2013 3:09:31 PM UTC-5, [avins...@gmail.com](mailto:avins...@gmail.com) wrote:

> I ran into the same issue and finally got it figured.
> 
> // This converts a Map
> 
> XContentBuilder b = SearchUtils._getDoc_(map);
> 
> UpdateRequestBuilder up = elasticClient.prepareUpdate(getIndexName(),  
> getIndexType(), id).
> 
> ```
> setConsistencyLevel(WriteConsistencyLevel.*DEFAULT*)
> 
> .setDoc(b)
> 
> .setUpsert(b);
> 
> ```
> 
> On Thursday, January 3, 2013 3:31:56 PM UTC-8, Tim Sheridan wrote:
> 
> > Trying to utilize the Upsert Java API without success. ES is running  
> > local standalone instance; connecting, indexing, and querying without  
> > problems. I'm using the UpdateRequestBuilder to prep the request and have  
> > tried the various forms of the setUpsert() API: setUpsert(XContentBuilder),  
> > setUpsert(Map source), setUpsert(IndexRequest). All result in a  
> > NullPointerException when execute() is called.
> > 
> > Here's the code:
> > 
> > try  
> > {  
> > NodeContent content = NodeContent.forJson();  
> > XContentBuilder builder = content.on( source ).adapt( adapter );
> > 
> > ```
> > // build the request
> > IndexRequest indexRequest = client
> > .prepareIndex( indexName, indexType )
> > .setSource( builder )
> > .request();
> > 
> > UpdateResponse response = client.prepareUpdate()
> > .setIndex( indexName )
> > .setType( indexType )
> > .setUpsert( indexRequest )
> > .execute()
> > .actionGet();
> > 
> > LOG.debug( String.format( "upserted content : %s : %s", 
> > 
> > ```
> > 
> > response.getId(), t ) );
> > 
> > ```
> > return NodeResult.minimal( response );
> > 
> > ```
> > 
> > }  
> > catch( Exception uhoh )  
> > {  
> > throw new NodeException( String.format( "failed to upsert content :  
> > %s : %s : %s", indexName, indexType, source.getId() ), uhoh );  
> > }
> > 
> > Here's the stacktrace:
> > 
> > 2013-01-03 18:19:57,863 ERROR (main) datastore.ElementDataStoreImpl\<135\>:  
> > failed to save element : [server2.lab.netuitive.com](http://server2.lab.netuitive.com)  
> > com.netuitive.collector.agent.node.NodeException: failed to upsert  
> > content : elements : element : null; nested exception is  
> > org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> > Failed execution  
> > at  
> > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:627)  
> > at  
> > com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElement(ElementDataStoreImpl.java:129)  
> > at  
> > com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElements(ElementDataStoreImpl.java:149)  
> > at  
> > com.netuitive.collector.element.datastore.ElementDataStoreTests.checkSaveElements(ElementDataStoreTests.java:66)  
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > at  
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > at  
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > at java.lang.reflect.Method.invoke(Method.java:597)  
> > at  
> > org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)  
> > at  
> > org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)  
> > at  
> > org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)  
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > at  
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > at  
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > at java.lang.reflect.Method.invoke(Method.java:597)  
> > at  
> > org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)  
> > at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)  
> > at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)  
> > at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)  
> > at  
> > org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)  
> > at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)  
> > at org.testng.TestRunner.privateRun(TestRunner.java:767)  
> > at org.testng.TestRunner.run(TestRunner.java:617)  
> > at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)  
> > at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)  
> > at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)  
> > at org.testng.SuiteRunner.run(SuiteRunner.java:240)  
> > at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  
> > at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)  
> > at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)  
> > at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)  
> > at org.testng.TestNG.run(TestNG.java:1036)  
> > at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)  
> > at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)  
> > at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)  
> > Caused by:  
> > org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> > Failed execution  
> > at  
> > org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)  
> > at  
> > org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)  
> > at  
> > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:619)  
> > ... 34 more  
> > Caused by: java.lang.NullPointerException  
> > at  
> > org.elasticsearch.common.io.stream.HandlesStreamOutput.writeString(HandlesStreamOutput.java:82)  
> > at  
> > org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:548)  
> > at  
> > org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:540)  
> > at  
> > org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:184)  
> > at  
> > org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:63)  
> > at  
> > org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:109)  
> > at  
> > org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:211)  
> > at  
> > org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)  
> > at  
> > org.elasticsearch.client.support.AbstractClient.update(AbstractClient.java:105)  
> > at  
> > org.elasticsearch.client.transport.TransportClient.update(TransportClient.java:318)  
> > at  
> > org.elasticsearch.action.update.UpdateRequestBuilder.doExecute(UpdateRequestBuilder.java:298)  
> > at  
> > org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
> > at  
> > org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
> > at  
> > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:618)  
> > ... 34 more
> > 
> > Am I using this API correctly? What am I missing? Any suggestions would  
> > be greatly appreciated.
> > 
> > Thanks  
> > Tim

--

---

<div class="post-metadata">

**Author:** ![avin](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@avin](https://discuss.elastic.co/u/avin)\
**Post date:** [January 5, 2013, 10:26pm UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/5 "2013-01-05T22:26:58Z")

</div>

Since its an update (although an upsert), the id is mandatory.

On Saturday, January 5, 2013 12:44:40 PM UTC-8, Tim Sheridan wrote:

> Cool. Your example provides an id when you prepare the update request. The  
> doc for the Upsert feature states it will create the document with the  
> provided if it doesn't already exists:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)
> 
> In that case, does this mean the id will be generated for you? If so, does  
> that mean the id an optional parameter on the call?
> 
> Thanks  
> Tim
> 
> On Saturday, January 5, 2013 3:09:31 PM UTC-5, [avins...@gmail.com](mailto:avins...@gmail.com) wrote:
> 
> > I ran into the same issue and finally got it figured.
> > 
> > // This converts a Map
> > 
> > XContentBuilder b = SearchUtils._getDoc_(map);
> > 
> > UpdateRequestBuilder up = elasticClient.prepareUpdate(getIndexName(),  
> > getIndexType(), id).
> > 
> > ```
> > setConsistencyLevel(WriteConsistencyLevel.*DEFAULT*)
> > 
> > .setDoc(b)
> > 
> > .setUpsert(b);
> > 
> > ```
> > 
> > On Thursday, January 3, 2013 3:31:56 PM UTC-8, Tim Sheridan wrote:
> > 
> > > Trying to utilize the Upsert Java API without success. ES is running  
> > > local standalone instance; connecting, indexing, and querying without  
> > > problems. I'm using the UpdateRequestBuilder to prep the request and have  
> > > tried the various forms of the setUpsert() API: setUpsert(XContentBuilder),  
> > > setUpsert(Map source), setUpsert(IndexRequest). All result in a  
> > > NullPointerException when execute() is called.
> > > 
> > > Here's the code:
> > > 
> > > try  
> > > {  
> > > NodeContent content = NodeContent.forJson();  
> > > XContentBuilder builder = content.on( source ).adapt( adapter );
> > > 
> > > ```
> > > // build the request
> > > IndexRequest indexRequest = client
> > > .prepareIndex( indexName, indexType )
> > > .setSource( builder )
> > > .request();
> > > 
> > > UpdateResponse response = client.prepareUpdate()
> > > .setIndex( indexName )
> > > .setType( indexType )
> > > .setUpsert( indexRequest )
> > > .execute()
> > > .actionGet();
> > > 
> > > LOG.debug( String.format( "upserted content : %s : %s", 
> > > 
> > > ```
> > > 
> > > response.getId(), t ) );
> > > 
> > > ```
> > > return NodeResult.minimal( response );
> > > 
> > > ```
> > > 
> > > }  
> > > catch( Exception uhoh )  
> > > {  
> > > throw new NodeException( String.format( "failed to upsert content :  
> > > %s : %s : %s", indexName, indexType, source.getId() ), uhoh );  
> > > }
> > > 
> > > Here's the stacktrace:
> > > 
> > > 2013-01-03 18:19:57,863 ERROR (main)  
> > > datastore.ElementDataStoreImpl\<135\>: failed to save element :  
> > > [server2.lab.netuitive.com](http://server2.lab.netuitive.com)  
> > > com.netuitive.collector.agent.node.NodeException: failed to upsert  
> > > content : elements : element : null; nested exception is  
> > > org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> > > Failed execution  
> > > at  
> > > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:627)  
> > > at  
> > > com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElement(ElementDataStoreImpl.java:129)  
> > > at  
> > > com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElements(ElementDataStoreImpl.java:149)  
> > > at  
> > > com.netuitive.collector.element.datastore.ElementDataStoreTests.checkSaveElements(ElementDataStoreTests.java:66)  
> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > at  
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > at  
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > at  
> > > org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)  
> > > at  
> > > org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)  
> > > at  
> > > org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)  
> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > at  
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > at  
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > at  
> > > org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)  
> > > at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)  
> > > at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)  
> > > at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)  
> > > at  
> > > org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)  
> > > at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)  
> > > at org.testng.TestRunner.privateRun(TestRunner.java:767)  
> > > at org.testng.TestRunner.run(TestRunner.java:617)  
> > > at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)  
> > > at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)  
> > > at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)  
> > > at org.testng.SuiteRunner.run(SuiteRunner.java:240)  
> > > at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  
> > > at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)  
> > > at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)  
> > > at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)  
> > > at org.testng.TestNG.run(TestNG.java:1036)  
> > > at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)  
> > > at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)  
> > > at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)  
> > > Caused by:  
> > > org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> > > Failed execution  
> > > at  
> > > org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)  
> > > at  
> > > org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)  
> > > at  
> > > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:619)  
> > > ... 34 more  
> > > Caused by: java.lang.NullPointerException  
> > > at  
> > > org.elasticsearch.common.io.stream.HandlesStreamOutput.writeString(HandlesStreamOutput.java:82)  
> > > at  
> > > org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:548)  
> > > at  
> > > org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:540)  
> > > at  
> > > org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:184)  
> > > at  
> > > org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:63)  
> > > at  
> > > org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:109)  
> > > at  
> > > org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:211)  
> > > at  
> > > org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)  
> > > at  
> > > org.elasticsearch.client.support.AbstractClient.update(AbstractClient.java:105)  
> > > at  
> > > org.elasticsearch.client.transport.TransportClient.update(TransportClient.java:318)  
> > > at  
> > > org.elasticsearch.action.update.UpdateRequestBuilder.doExecute(UpdateRequestBuilder.java:298)  
> > > at  
> > > org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
> > > at  
> > > org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
> > > at  
> > > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:618)  
> > > ... 34 more
> > > 
> > > Am I using this API correctly? What am I missing? Any suggestions would  
> > > be greatly appreciated.
> > > 
> > > Thanks  
> > > Tim

--

---

<div class="post-metadata">

**Author:** ![avin](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@avin](https://discuss.elastic.co/u/avin)\
**Post date:** [January 6, 2013, 12:14am UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/6 "2013-01-06T00:14:26Z")

</div>

You can also do something like:

UpdateRequestBuilder up = elasticClient.prepareUpdate(getIndexName(),  
getIndexType(), id).

```
    setConsistencyLevel(WriteConsistencyLevel.*DEFAULT*)

    .setDoc(map)

    .setUpsert(map);

```

On Saturday, January 5, 2013 2:26:58 PM UTC-8, [avins...@gmail.com](mailto:avins...@gmail.com) wrote:

> Since its an update (although an upsert), the id is mandatory.
> 
> On Saturday, January 5, 2013 12:44:40 PM UTC-8, Tim Sheridan wrote:
> 
> > Cool. Your example provides an id when you prepare the update request.  
> > The doc for the Upsert feature states it will create the document with the  
> > provided if it doesn't already exists:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)
> > 
> > In that case, does this mean the id will be generated for you? If so,  
> > does that mean the id an optional parameter on the call?
> > 
> > Thanks  
> > Tim
> > 
> > On Saturday, January 5, 2013 3:09:31 PM UTC-5, [avins...@gmail.com](mailto:avins...@gmail.com) wrote:
> > 
> > > I ran into the same issue and finally got it figured.
> > > 
> > > // This converts a Map
> > > 
> > > XContentBuilder b = SearchUtils._getDoc_(map);
> > > 
> > > UpdateRequestBuilder up = elasticClient.prepareUpdate(getIndexName(),  
> > > getIndexType(), id).
> > > 
> > > ```
> > > setConsistencyLevel(WriteConsistencyLevel.*DEFAULT*)
> > > 
> > > .setDoc(b)
> > > 
> > > .setUpsert(b);
> > > 
> > > ```
> > > 
> > > On Thursday, January 3, 2013 3:31:56 PM UTC-8, Tim Sheridan wrote:
> > > 
> > > > Trying to utilize the Upsert Java API without success. ES is running  
> > > > local standalone instance; connecting, indexing, and querying without  
> > > > problems. I'm using the UpdateRequestBuilder to prep the request and have  
> > > > tried the various forms of the setUpsert() API: setUpsert(XContentBuilder),  
> > > > setUpsert(Map source), setUpsert(IndexRequest). All result in a  
> > > > NullPointerException when execute() is called.
> > > > 
> > > > Here's the code:
> > > > 
> > > > try  
> > > > {  
> > > > NodeContent content = NodeContent.forJson();  
> > > > XContentBuilder builder = content.on( source ).adapt( adapter );
> > > > 
> > > > ```
> > > > // build the request
> > > > IndexRequest indexRequest = client
> > > > .prepareIndex( indexName, indexType )
> > > > .setSource( builder )
> > > > .request();
> > > > 
> > > > UpdateResponse response = client.prepareUpdate()
> > > > .setIndex( indexName )
> > > > .setType( indexType )
> > > > .setUpsert( indexRequest )
> > > > .execute()
> > > > .actionGet();
> > > > 
> > > > LOG.debug( String.format( "upserted content : %s : %s", 
> > > > 
> > > > ```
> > > > 
> > > > response.getId(), t ) );
> > > > 
> > > > ```
> > > > return NodeResult.minimal( response );
> > > > 
> > > > ```
> > > > 
> > > > }  
> > > > catch( Exception uhoh )  
> > > > {  
> > > > throw new NodeException( String.format( "failed to upsert content :  
> > > > %s : %s : %s", indexName, indexType, source.getId() ), uhoh );  
> > > > }
> > > > 
> > > > Here's the stacktrace:
> > > > 
> > > > 2013-01-03 18:19:57,863 ERROR (main)  
> > > > datastore.ElementDataStoreImpl\<135\>: failed to save element :  
> > > > [server2.lab.netuitive.com](http://server2.lab.netuitive.com)  
> > > > com.netuitive.collector.agent.node.NodeException: failed to upsert  
> > > > content : elements : element : null; nested exception is  
> > > > org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> > > > Failed execution  
> > > > at  
> > > > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:627)  
> > > > at  
> > > > com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElement(ElementDataStoreImpl.java:129)  
> > > > at  
> > > > com.netuitive.collector.element.datastore.ElementDataStoreImpl.saveElements(ElementDataStoreImpl.java:149)  
> > > > at  
> > > > com.netuitive.collector.element.datastore.ElementDataStoreTests.checkSaveElements(ElementDataStoreTests.java:66)  
> > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > > at  
> > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > > at  
> > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > > at  
> > > > org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)  
> > > > at  
> > > > org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:182)  
> > > > at  
> > > > org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)  
> > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > > at  
> > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > > at  
> > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > > at  
> > > > org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)  
> > > > at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)  
> > > > at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)  
> > > > at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)  
> > > > at  
> > > > org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)  
> > > > at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)  
> > > > at org.testng.TestRunner.privateRun(TestRunner.java:767)  
> > > > at org.testng.TestRunner.run(TestRunner.java:617)  
> > > > at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)  
> > > > at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)  
> > > > at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)  
> > > > at org.testng.SuiteRunner.run(SuiteRunner.java:240)  
> > > > at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  
> > > > at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)  
> > > > at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)  
> > > > at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)  
> > > > at org.testng.TestNG.run(TestNG.java:1036)  
> > > > at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)  
> > > > at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)  
> > > > at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)  
> > > > Caused by:  
> > > > org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:  
> > > > Failed execution  
> > > > at  
> > > > org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)  
> > > > at  
> > > > org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)  
> > > > at  
> > > > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:619)  
> > > > ... 34 more  
> > > > Caused by: java.lang.NullPointerException  
> > > > at  
> > > > org.elasticsearch.common.io.stream.HandlesStreamOutput.writeString(HandlesStreamOutput.java:82)  
> > > > at  
> > > > org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:548)  
> > > > at  
> > > > org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:540)  
> > > > at  
> > > > org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:184)  
> > > > at  
> > > > org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:63)  
> > > > at  
> > > > org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:109)  
> > > > at  
> > > > org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:211)  
> > > > at  
> > > > org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)  
> > > > at  
> > > > org.elasticsearch.client.support.AbstractClient.update(AbstractClient.java:105)  
> > > > at  
> > > > org.elasticsearch.client.transport.TransportClient.update(TransportClient.java:318)  
> > > > at  
> > > > org.elasticsearch.action.update.UpdateRequestBuilder.doExecute(UpdateRequestBuilder.java:298)  
> > > > at  
> > > > org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
> > > > at  
> > > > org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
> > > > at  
> > > > com.netuitive.collector.agent.node.NodeTemplate.upsert(NodeTemplate.java:618)  
> > > > ... 34 more
> > > > 
> > > > Am I using this API correctly? What am I missing? Any suggestions would  
> > > > be greatly appreciated.
> > > > 
> > > > Thanks  
> > > > Tim

--

---

<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 6, 2017, 2:57am UTC](https://discuss.elastic.co/t/npe-with-upsert-java-api/10224/7 "2017-07-06T02:57:45Z")

</div>


