I got the same exception. In my case I wanted to index a parent
document and then the child document with the same client. Example:
Client client = this.elasticNode.client();
XContentBuilder builder = XContentFactory.jsonBuilder();
Map map;
IndexRequestBuilder irb
map = new HashMap<String,Object>();
map.put("foo", "foo");
client.prepareIndex("myindex", "mytype",
"1").setSource(builder.map(map).execute().actionGet();
map = new HashMap<String,Object>();
map.put("bar", "bar");
client.prepareIndex("myindex", "childtype", "1");
builder = XContentFactory.jsonBuilder();
irb = client.prepareIndex("myindex", "mytype", "1");
irb = irb.setParent("1");
irb = irb.setSource(builder.map(map);
irb = irb.execute().actionGet();
The NPE is thrown when we call prepareIndex the second time. Note that
removing the id allows that call to succeed, but then a subsequent
call fails (either setParent or setSource, I forget which.) I was able
to work around it by closing and recreating the client:
Client client = this.elasticNode.client();
XContentBuilder builder = XContentFactory.jsonBuilder();
Map map;
IndexRequestBuilder irb
map = new HashMap<String,Object>();
map.put("foo", "foo");
client.prepareIndex("myindex", "mytype",
"1").setSource(builder.map(map).execute().actionGet();
client.close();
map = new HashMap<String,Object>();
map.put("bar", "bar");
client = this.elasticNode.client();
client.prepareIndex("myindex", "childtype", "1");
builder = XContentFactory.jsonBuilder();
irb = client.prepareIndex("myindex", "mytype", "1");
irb = irb.setParent("1");
irb = irb.setSource(builder.map(map);
irb = irb.execute().actionGet();
client.close();
On Mar 8, 1:37 am, Shay Banon shay.ba...@elasticsearch.com wrote:
Its a bit hard to tell where the failure is, since it relies on your code that converts the object. If you can create a simple test case that fails with just the builder, it would help.On Tuesday, March 8, 2011 at 10:31 AM, dpilato wrote: