You can use the Update API with a script to append to the array:
curl -XPOST "http://localhost:9200/t/t/1" -d'
{
"hobbies" : ["a", "b"]
}'
curl -XPOST "http://localhost:9200/t/t/1/_update" -d'
{
"script" : "ctx._source.hobbies += hobby",
"params" : {
"hobby" : "c"
}
}'
curl -XGET "http://localhost:9200/t/t/1"
You can even append an array to the array:
curl -XPOST "http://localhost:9200/t/t/1/_update" -d'
{
"script" : "ctx._source.hobbies += hobby",
"params" : {
"hobby" : ["d", "e"]
}
}'
-Zach
On Tuesday, March 18, 2014 8:46:27 AM UTC-4, James Massey wrote:
In looking at the Elasticsearch documentation, specifically the Update
API, it doesn't appear that Elasticsearch has the functionality to append
to an array, it can "update" it with new values, but not preserve the
existing values. Am I correct in saying this?
For an example of what I'm trying to figure out, I borrowed an example
from Exploring Elasticsearch. If I have data that looks like the following:
"_id": 1,
"handle": "ron",
"age": 28,
"hobbies": ["hacking", "the great outdoors"],
"computer": {"cpu": "pentium pro", "mhz": 200}
Is there any way to add "cooking" to the list of hobbies without deleting "hacking" and "the great outdoors" within Elasticsearch itself?
On Tuesday, March 18, 2014 8:46:27 AM UTC-4, James Massey wrote:
In looking at the Elasticsearch documentation, specifically the Update
API, it doesn't appear that Elasticsearch has the functionality to append
to an array, it can "update" it with new values, but not preserve the
existing values. Am I correct in saying this?
For an example of what I'm trying to figure out, I borrowed an example
from Exploring Elasticsearch. If I have data that looks like the following:
"_id": 1,
"handle": "ron",
"age": 28,
"hobbies": ["hacking", "the great outdoors"],
"computer": {"cpu": "pentium pro", "mhz": 200}
Is there any way to add "cooking" to the list of hobbies without deleting "hacking" and "the great outdoors" within Elasticsearch itself?
--
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/3a2f8db5-1b45-48be-b641-b41a1728d55b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.