Update existing values within a list or array in Elastic Search

I have a requirement where I need to update(not append) existing values
within a list or array in Elastic Search.
Is this feature supported in elastic search?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different
values.
Currently I am only able to append a job but I cannot update the attributes
of each job later.
Is this usecase supported and possible in Elastic Search?

--
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/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

If you send the full document without the element you need to remove in the array, this should work fine.
How do you actually update your document?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita.sadhukhan@gmail.com) a écrit:

I have a requirement where I need to update(not append) existing values within a list or array in Elastic Search.
Is this feature supported in elastic search?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different values.
Currently I am only able to append a job but I cannot update the attributes of each job later.
Is this usecase supported and possible in Elastic Search?

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/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/etPan.53a92849.66334873.950f%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/d/optout.

I am not removing any element from an array I need to update particular
existing elements within an array.
Currently I ma using the Update API in Elastic Search to append new
elements within the array but it fails when I try to update values of
existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API
scripts

{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},

What I need is how to update orderId value from 'undefined' to say 'abcd'
using update api.
Is this supported?
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:

If you send the full document without the element you need to remove in
the array, this should work fine.
How do you actually update your document?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com
<javascript:>) a écrit:

I have a requirement where I need to update(not append) existing values
within a list or array in Elastic Search.
Is this feature supported in Elasticsearch?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different
values.
Currently I am only able to append a job but I cannot update the
attributes of each job later.
Is this usecase supported and possible in Elastic Search?

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:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Just send the full new version of your document and you're done.
Elasticsearch will index the new content.

If I did not answer to you question, may be you should provide an example as a Gist so we can comment with more details???

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr

Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan (madhumita.sadhukhan@gmail.com) a écrit:

I am not removing any element from an array I need to update particular existing elements within an array.
Currently I ma using the Update API in Elastic Search to append new elements within the array but it fails when I try to update values of existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API scripts

{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},

What I need is how to update orderId value from 'undefined' to say 'abcd' using update api.
Is this supported?
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:
If you send the full document without the element you need to remove in the array, this should work fine.
How do you actually update your document?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com) a écrit:

I have a requirement where I need to update(not append) existing values within a list or array in Elastic Search.
Is this feature supported in elastic search?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different values.
Currently I am only able to append a job but I cannot update the attributes of each job later.
Is this usecase supported and possible in Elastic Search?

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/etPan.53a95aab.3352255a.950f%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/d/optout.

I also have the same question, I have a array type field in my document of
Elasticsearch, like below:-

"prog_lists": [
{
"description": "engineer",
"age": 25,
"name": "ashu"
},
{
"description": "programmer",
"age": 26,
"name": "rajit"
},
{
"description": "designer",
"age": 27,
"name": "naveen"
}]

I want to update only one object from this array i.e. i want to query where
name equals to ashu then update his age to 30. How I can achieve this in
Elasticsearch

please suggest something...

On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:

Just send the full new version of your document and you're done.
Elasticsearch will index the new content.

If I did not answer to you question, may be you should provide an example
as a Gist so we can comment with more details???

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan (madhumita...@gmail.com
<javascript:>) a écrit:

I am not removing any element from an array I need to update particular
existing elements within an array.
Currently I ma using the Update API in Elastic Search to append new
elements within the array but it fails when I try to update values of
existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API
scripts

{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},

What I need is how to update orderId value from 'undefined' to say 'abcd'
using update api.
Is this supported?
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:

If you send the full document without the element you need to remove in
the array, this should work fine.
How do you actually update your document?

  -- 

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com)
a écrit:

I have a requirement where I need to update(not append) existing values
within a list or array in Elastic Search.
Is this feature supported in Elasticsearch?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different
values.
Currently I am only able to append a job but I cannot update the
attributes of each job later.
Is this usecase supported and possible in Elastic Search?

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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/4d5ea21f-dbb7-4fd0-9649-8e0131357738%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 Tuesday, October 7, 2014 6:38:38 PM UTC+5:30, Rajit Garg wrote:

I also have the same question, I have a array type field in my document
of Elasticsearch, like below:-

"prog_lists": [
{
"description": "engineer",
"age": 25,
"name": "ashu"
},
{
"description": "programmer",
"age": 26,
"name": "rajit"
},
{
"description": "designer",
"age": 27,
"name": "naveen"
}]

I want to update only one object from this array i.e. i want to query
where name equals to ashu then update his age to 30. How I can achieve
this in Elasticsearch

please suggest something...

On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:

Just send the full new version of your document and you're done.
Elasticsearch will index the new content.

If I did not answer to you question, may be you should provide an example
as a Gist so we can comment with more details???

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan (madhumita...@gmail.com)
a écrit:

I am not removing any element from an array I need to update particular
existing elements within an array.
Currently I ma using the Update API in Elastic Search to append new
elements within the array but it fails when I try to update values of
existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API
scripts

{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},

What I need is how to update orderId value from 'undefined' to say 'abcd'
using update api.
Is this supported?
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:

If you send the full document without the element you need to remove
in the array, this should work fine.
How do you actually update your document?

  -- 

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com)
a écrit:

I have a requirement where I need to update(not append) existing
values within a list or array in Elastic Search.
Is this feature supported in Elasticsearch?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different
values.
Currently I am only able to append a job but I cannot update the
attributes of each job later.
Is this usecase supported and possible in Elastic Search?

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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/3fc06c06-656d-4fe9-94d9-07f3d8f6f9e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I have got my answer, and its solution is

POST /twitter/twit/1/_update

{
  "script": "item_to_remove = nil; foreach (item : ctx._source.list) { 

if (item['tweet_id'] == tweet_id) { item_to_remove=item; } } if
(item_to_remove != nil) ctx._source.list.remove(item_to_remove);",
"params": {"tweet_id": "123"}
}

if you have more than one item that matches the criteria, use a list
instead:

POST /twitter/twit/1/_update
{
  "script": "items_to_remove = []; foreach (item : ctx._source.list) { 

if (item['tweet_id'] == tweet_id) { items_to_remove.add(item); } } foreach
(item : items_to_remove) {ctx._source.list.remove(item);}",
"params": {"tweet_id": "123"}
}

On Tuesday, June 24, 2014 12:48:17 PM UTC+5:30, Madhumita Sadhukhan wrote:

I have a requirement where I need to update(not append) existing values
within a list or array in Elastic Search.
Is this feature supported in Elasticsearch?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different
values.
Currently I am only able to append a job but I cannot update the
attributes of each job later.
Is this usecase supported and possible in Elastic Search?

On Wednesday, October 8, 2014 4:41:45 PM UTC+5:30, Rajit Garg wrote:

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 Tuesday, October 7, 2014 6:38:38 PM UTC+5:30, Rajit Garg wrote:

I also have the same question, I have a array type field in my document
of Elasticsearch, like below:-

"prog_lists": [
{
"description": "engineer",
"age": 25,
"name": "ashu"
},
{
"description": "programmer",
"age": 26,
"name": "rajit"
},
{
"description": "designer",
"age": 27,
"name": "naveen"
}]

I want to update only one object from this array i.e. i want to query
where name equals to ashu then update his age to 30. How I can achieve
this in Elasticsearch

please suggest something...

On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:

Just send the full new version of your document and you're done.
Elasticsearch will index the new content.

If I did not answer to you question, may be you should provide an
example as a Gist so we can comment with more details???

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan (madhumita...@gmail.com)
a écrit:

I am not removing any element from an array I need to update particular
existing elements within an array.
Currently I ma using the Update API in Elastic Search to append new
elements within the array but it fails when I try to update values of
existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API
scripts

{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},

What I need is how to update orderId value from 'undefined' to say
'abcd' using update api.
Is this supported?
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:

If you send the full document without the element you need to remove
in the array, this should work fine.
How do you actually update your document?

  -- 

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com)
a écrit:

I have a requirement where I need to update(not append) existing
values within a list or array in Elastic Search.
Is this feature supported in Elasticsearch?

For eg:

I have a field called jobs as part of my document

"jobs": [
{
"status": "InProgress",
"runId": 1,
"start_date": 2101112,
"orderId": "undefined"
},
{
"status": "InProgress",
"runId": 2,
"start_date": 2101112,
"orderId": "undefined"
},
],
and I am required to update the orderId for each job run to different
values.
Currently I am only able to append a job but I cannot update the
attributes of each job later.
Is this usecase supported and possible in Elastic Search?

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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/df051e8d-26a6-4e96-a021-27dc74d8d091%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.