NPE with Upsert Java API

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
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

--

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
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

--

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
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

--

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:

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 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
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

--

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

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 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
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

--

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 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

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 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
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

--