Delete/update nested documents with elasticsearch Java API

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users property
(nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", "store":"yes", 
    

"index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer", customerId)
updateRequest.script(" if (ctx._source.users == null) { ctx._source.users =
"+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the *customer root type

  • document.

How is it to be done for deleting or *updating *a specific user ID from
the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

It is a bit tricky, but you can remove elements from your users nested
field by using a for loop as script with the update api.
Something like this should work:
curl -s -XPOST 'localhost:9200/test/customer/1/_update' -d '{
"script" : "for (int i = 0; i < ctx._source.users.size();
i++){if(ctx._source.users[i]._id == id){ctx._source.users.remove(i);}}",
"params" : {
"id" : "1"
}
}'

In the above case the user with _id value 1 should be removed.

On 10 April 2013 08:52, Andrei Tolnai dreytc@gmail.com wrote:

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users
property (nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes",
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes",
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", "store":"yes",
    

"index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer", customerId)
updateRequest.script(" if (ctx._source.users == null) { ctx._source.users
= "+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the customer root
type
document.

How is it to be done for deleting or *updating *a specific user ID from
the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks for the reply Martijn!

The DELETE/REMOVE of a user does not work for me; I don't get any error
either its just that the specific user ID I put in its just not getting
removed.

However I was able to do the UPDATE for a specific user ID by adapting a
bit your DELETE script into:

for (int i = 0; i < ctx._source.users.size();
i++){if(ctx._source.users[i]._id ==
"1"){ctx._source.users[i]= "_id":"1","name":"Updated
John","birthDate":"2013-04-11T15:27:31.218Z" ;}}

Any other clues on how I should do the remove an entry from a nested array
using ES Java API?

Thanks.

On Wednesday, April 10, 2013 1:51:49 PM UTC+3, Martijn v Groningen wrote:

It is a bit tricky, but you can remove elements from your users nested
field by using a for loop as script with the update api.
Something like this should work:
curl -s -XPOST 'localhost:9200/test/customer/1/_update' -d '{
"script" : "for (int i = 0; i < ctx._source.users.size();
i++){if(ctx._source.users[i]._id == id){ctx._source.users.remove(i);}}",
"params" : {
"id" : "1"
}
}'

In the above case the user with _id value 1 should be removed.

On 10 April 2013 08:52, Andrei Tolnai <dre...@gmail.com <javascript:>>wrote:

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users
property (nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", 
    

"store":"yes", "index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer", customerId)
updateRequest.script(" if (ctx._source.users == null) { ctx._source.users
= "+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the customer root
type
document.

How is it to be done for deleting or *updating *a specific user ID
from the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

"for (int i = 0; i < ctx._source.users.size();
i++){if(ctx._source.users[i]._id == id){ctx._source.users.remove(i);}}",

I am not 100% sure but I think the issue about DELETE script is around the
last part: ctx._source.users.remove(i);

Could we do that remove by specifying there the the _id of the user we
want to delete from the nested array?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Oddly enough the DELETE script seems to be working if in the array there is
only one user with a particular given id. :slight_smile:

If I have multiple users with the same _id value the script is not
removing all of them. How should the script be changed to remove all the
users that have a specific _id value?

Regards.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Andrei,

I think the following should work:
"script" : "for (int i = 0; i < ctx._source.users.size();
i++){if(ctx._source.users[i]._id == id){ctx._source.users.remove(i);i--;}}"

I added: 'i--'. Once an entry is removed, the list has been shorter and we
shouldn't skip over the next entry.

Martijn

On 11 April 2013 18:04, Andrei Tolnai dreytc@gmail.com wrote:

Oddly enough the DELETE script seems to be working if in the array there
is only one user with a particular given id. :slight_smile:

If I have multiple users with the same _id value the script is not
removing all of them. How should the script be changed to remove all the
users that have a specific _id value?

Regards.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Great, that worked! Thanks Martijn!

Now I have to figure out how to do a retrieve for a specific user id using
the Java API and org.elasticsearch.action.get.GetRequest

Regards

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hello,

I am using Spring data elasticsearchhttps://github.com/BioMedCentralLtd/spring-data-elasticsearch in
my project and I need to update an Indexed field. Is it possible to do this
using this framework??

On Wednesday, April 10, 2013 12:22:14 PM UTC+5:30, Andrei Tolnai wrote:

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users
property (nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", "store":"yes", 
    

"index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer", customerId)
updateRequest.script(" if (ctx._source.users == null) { ctx._source.users
= "+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the customer root
type
document.

How is it to be done for deleting or *updating *a specific user ID from
the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

I have tried to update or remove the nested object in the same way as
suggested , but this is not working

I am doing this

client.update({"index": "daffosw","type": "daffo","id": "2501","body": {
"script" : "for (int i = 0; i < ctx._source.users.size(); i++){
if(ctx._source.users[i]_id == id){
ctx._source.users[i].name = 'Updated John';
}
}",
"params" : {
"id" : "1"
}
}}

my users field contain the following

"users": [
{
"code": "abcd",
"_id": "1",
"name": "naveen"
},
{
"code": "efgh",
"_id": "2",
"name": "rajit"
},
{
"code": "ijkl",
"_id": "3",
"name": "ashu"
}
]

and I am getting this error

VerifyError[Bad type on operand stack
Exception Details:
Location:
ASMAccessorImpl_11232799721412745799160.setValue(Ljava/lang/Object;Ljava/lang/Object;Lorg/elasticsearch/common/mvel2/integration/VariableResolverFactory;Ljava/lang/Object;)Ljava/lang/Object; @49: invokeinterface
Reason:
Type 'java/lang/Object' (current frame, stack[1]) is not assignable to integer
Current Frame:
bci: @49
flags: { }
locals: { 'ASMAccessorImpl_11232799721412745799160', 'java/lang/Object', 'java/lang/Object', 'org/elasticsearch/common/mvel2/integration/VariableResolverFactory', 'java/lang/Object' }
stack: { 'java/util/List', 'java/lang/Object' }
Bytecode:
0000000: 2d12 0eb9 0014 0200 b900 1a01 00c0 001c
0000010: 121e b900 2202 00c0 001c 1224 b900 2202
0000020: 00c0 0026 2d12 28b9 0014 0200 b900 1a01
0000030: 00b9 002b 0200 c000 2d12 2f19 04b6 0035
0000040: 1904 b0
]
Error: VerifyError[Bad type on operand stack
Exception Details:
Location:----------------------------



On Friday, April 12, 2013 1:16:33 AM UTC+5:30, Martijn v Groningen wrote:

Hi Andrei,

I think the following should work:
"script" : "for (int i = 0; i < ctx._source.users.size();
i++){if(ctx._source.users[i]._id == id){ctx._source.users.remove(i);i--;}}"

I added: 'i--'. Once an entry is removed, the list has been shorter and we
shouldn't skip over the next entry.

Martijn

On 11 April 2013 18:04, Andrei Tolnai <dre...@gmail.com <javascript:>>
wrote:

Oddly enough the DELETE script seems to be working if in the array there
is only one user with a particular given id. :slight_smile:

If I have multiple users with the same _id value the script is not
removing all of them. How should the script be changed to remove all the
users that have a specific _id value?

Regards.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5671672d-cc4e-451b-93a6-e40b574ea467%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hey

I figured it out, I am able to update but I am not able to remove object
that satisfies the condition

PUT twitter/twit/1
{
"list": [
{
"tweet_id": "1",
"a": "b"
},
{
"tweet_id": "123",
"a": "f"
}
]
}

POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) { item['new_field'] = 'ghi'; } }",
"params": {
"tweet_id": "123"
}
}
this is working

for remove i am doing this

POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) {ctx._source.list.remove(item); } }",
"params": {
"tweet_id": "123"
}
}

*but this is not working and giving this error, *

ElasticsearchIllegalArgumentException[failed to execute script]; nested:
ConcurrentModificationException;
Error: ElasticsearchIllegalArgumentException[failed to execute script];
nested: ConcurrentModificationException;
..................................
...............................

please help........

On Wednesday, April 10, 2013 12:22:14 PM UTC+5:30, Andrei Tolnai wrote:

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users
property (nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", "store":"yes", 
    

"index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer", customerId)
updateRequest.script(" if (ctx._source.users == null) { ctx._source.users
= "+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the customer root
type
document.

How is it to be done for deleting or *updating *a specific user ID from
the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/171950f9-5843-4327-be49-b6858e1b3832%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

"script": "removeObjects = new java.util.ArrayList(); foreach (item :
ctx._source.list) {if (item['tweet_id'] == tweet_id)
{removeObjects.add(item) } }
for(removeObject:removeObjects){ctx._source.list.remove(removeObject);}",

2014년 10월 8일 수요일 오후 8시 12분 55초 UTC+9, Rajit Garg 님의 말:

Hey

I figured it out, I am able to update but I am not able to remove object
that satisfies the condition

PUT twitter/twit/1
{
"list": [
{
"tweet_id": "1",
"a": "b"
},
{
"tweet_id": "123",
"a": "f"
}
]
}

POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) { item['new_field'] = 'ghi'; } }",
"params": {
"tweet_id": "123"
}
}
this is working

for remove i am doing this

POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) {ctx._source.list.remove(item); } }",
"params": {
"tweet_id": "123"
}
}

*but this is not working and giving this error, *

ElasticsearchIllegalArgumentException[failed to execute script]; nested:
ConcurrentModificationException;
Error: ElasticsearchIllegalArgumentException[failed to execute script];
nested: ConcurrentModificationException;
..................................
...............................

please help........

On Wednesday, April 10, 2013 12:22:14 PM UTC+5:30, Andrei Tolnai wrote:

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users
property (nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", "store":"yes", 
    

"index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer", customerId)
updateRequest.script(" if (ctx._source.users == null) { ctx._source.users
= "+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the customer root
type
document.

How is it to be done for deleting or *updating *a specific user ID
from the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8ef09dca-306d-4fa7-8936-a20e86125dac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks this is working

On Tuesday, October 28, 2014 8:40:12 AM UTC+5:30, shar...@gmail.com wrote:

"script": "removeObjects = new java.util.ArrayList(); foreach (item :
ctx._source.list) {if (item['tweet_id'] == tweet_id)
{removeObjects.add(item) } }
for(removeObject:removeObjects){ctx._source.list.remove(removeObject);}",

2014년 10월 8일 수요일 오후 8시 12분 55초 UTC+9, Rajit Garg 님의 말:

Hey

I figured it out, I am able to update but I am not able to remove object
that satisfies the condition

PUT twitter/twit/1
{
"list": [
{
"tweet_id": "1",
"a": "b"
},
{
"tweet_id": "123",
"a": "f"
}
]
}

POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) { item['new_field'] = 'ghi'; } }",
"params": {
"tweet_id": "123"
}
}
this is working

for remove i am doing this

POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) {ctx._source.list.remove(item); } }",
"params": {
"tweet_id": "123"
}
}

*but this is not working and giving this error, *

ElasticsearchIllegalArgumentException[failed to execute script]; nested:
ConcurrentModificationException;
Error: ElasticsearchIllegalArgumentException[failed to execute script];
nested: ConcurrentModificationException;
..................................
...............................

please help........

On Wednesday, April 10, 2013 12:22:14 PM UTC+5:30, Andrei Tolnai wrote:

Hello.

I use *Elastic Search Java API *for basic *CRUD *operations on ES
documents; with root type documents it is working fine.

However when I want to delete a nested document, I don't know how to use
the Java API and scripting that *Elastic Search *provides.

I have the following root type document which has in it a nested *users
property (nested document).
{
"customer":
{
"_all" : {"enabled" : false},
"_source" : {"enabled" : true},
"store" : "true",
"properties":
{
"location" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
"comments" : { "type": "string", "store": "yes",
"index":"not_analyzed" },
* "users":

  •              {*
    
  •                 "type":"nested",*
    
  •                 "store":"yes", *
    
  •                 "properties":*
    
  •                    {*
    
  •                       "_id" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "name" : { "type":"string", "store":"yes", 
    

"index":"not_analyzed" },*

  •                       "birthDate" : { "type":"date", 
    

"store":"yes", "index":"not_analyzed" }*

  •                    }*
    
  •              }*
          }
    }
    

}

If I want to add a user I do the following in *Java */ *Scala *code:

val json = "
{"_id":"1","name":"Anthony","birthDate":"2013-04-10T06:45:26.186Z"}"
val updateRequest = new UpdateRequest("indexName", "customer",
customerId)
updateRequest.script(" if (ctx._source.users == null) {
ctx._source.users = "+json+" } else { ctx._source.users += "+json+" } ")

This works OK for adding nested *users *AKA updating the customer root
type
document.

How is it to be done for deleting or *updating *a specific user ID
from the nested users nested document?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a4ccc10c-a06e-4c47-b486-8fdd1da4bfa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.