avin
December 19, 2012, 5:11am
1
Newbie here.
I am trying to create an index using upsert
curl -XPOST 'localhost:9200/metadata/load/ind1/_update' -d '{
"script" : "ctx.op = "none"",
"upsert" : {
doc: {"Key1" : "Value1"}
}
}'
Output:
{"ok":true,"_index":"metadata","_type":"load","_id":"ind1","_version":1}
Now what I actually want to do is to add another Value to the index.
curl -XPOST 'localhost:9200/metadata/load/ind1/_update' -d '{
"script" : "ctx.op = "none"",
"upsert" : {
doc: {"Key2" : "Value2"}
}
}'
However, the source doc doesn't get updated with these new values.
What am I doing wrong here.
--
avin
December 19, 2012, 5:14am
2
When I try this:
curl -XPOST 'localhost:9200/metadata/load/ind1/_update' -d '{
doc: {"Key3" : "Value3"},
"upsert" : {
}
}'
I find that the source actually got updated.
"_source" : {"doc":{"Key1":"Value1"},"Key2":"Value2","Key3":"Value3"}}]}}
On Tuesday, December 18, 2012 9:11:02 PM UTC-8, avins...@gmail.com wrote:
Newbie here.
I am trying to create an index using upsert
curl -XPOST 'localhost:9200/metadata/load/ind1/_update' -d '{
"script" : "ctx.op = "none"",
"upsert" : {
doc: {"Key1" : "Value1"}
}
}'
Output:
{"ok":true,"_index":"metadata","_type":"load","_id":"ind1","_version":1}
Now what I actually want to do is to add another Value to the index.
curl -XPOST 'localhost:9200/metadata/load/ind1/_update' -d '{
"script" : "ctx.op = "none"",
"upsert" : {
doc: {"Key2" : "Value2"}
}
}'
However, the source doc doesn't get updated with these new values.
What am I doing wrong here.
--
Hello,
AFAIK, what you put in "upsert" is done only if the document doesn't exist.
For example, if you simply want to add a new field to an existing doc, this
should work:
curl -XPOST localhost:9200/test/test/1/_update -d '
{
"script": "ctx._source.field1 = "value1"",
}'
But that would fail if the document is missing. So just in case it's not
there, you can add an initial doc in the upsert section. For example:
curl -XPOST localhost:9200/test/test/3/_update -d '
{
"script": "ctx._source.field1 = "value1"",
"upsert": {
"field1": "value1",
"field2": "value2"
}
}'
Best regards,
Radu
http://sematext.com/ -- Elasticsearch -- Solr -- Lucene
On Wed, Dec 19, 2012 at 7:14 AM, avinsemail@gmail.com wrote:
When I try this:
curl -XPOST 'localhost:9200/metadata/load/ind1/_update' -d '{
doc: {"Key3" : "Value3"},
"upsert" : {
}
}'
I find that the source actually got updated.
"_source" : {"doc":{"Key1":"Value1"},"Key2":"Value2","Key3":"Value3"}}]}}
On Tuesday, December 18, 2012 9:11:02 PM UTC-8, avins...@gmail.com wrote:
Newbie here.
I am trying to create an index using upsert
curl -XPOST 'localhost:9200/metadata/load/**ind1/_update' -d '{
"script" : "ctx.op = "none"",
"upsert" : {
doc: {"Key1" : "Value1"}
}
}'
Output:
{"ok":true,"_index":"metadata","_type":"load","_id":"ind1","
_version":1}
Now what I actually want to do is to add another Value to the index.
curl -XPOST 'localhost:9200/metadata/load/**ind1/_update' -d '{
"script" : "ctx.op = "none"",
"upsert" : {
doc: {"Key2" : "Value2"}
}
}'
However, the source doc doesn't get updated with these new values.
What am I doing wrong here.
--
--