Conditional scripting during bulk update

I'm trying to have a script that will update a particular field (vcounter)
only if the index version is "1" during a bulk request. Here's a single
index in the bulk that will be upserted.

I only want to set the vcounter field to 1 ONLY if the index is at version
1 - else it will be incremented:

{"update": {"_id": "1"}}
{"upsert": {"vcounter": 0}, "script": "if (ctx._version == '1') {
ctx._source.vcounter = 1 } else { ctx._source.vcounter += 1"}
{"update": {"_id": "1"}}
{"doc": {"field2": 3, "field1": "value1"}, "doc_as_upsert": true}

Can't figure out what the problem is. Not even sure if we can script
against the _version field? The above command always leaves vcounter at 0.

Any pointers would be much appreciated.

G

--
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.

Is _version field supported in scripts.

On Tuesday, 20 August 2013 06:29:02 UTC+5:30, GivP wrote:

I'm trying to have a script that will update a particular field (vcounter)
only if the index version is "1" during a bulk request. Here's a single
index in the bulk that will be upserted.

I only want to set the vcounter field to 1 ONLY if the index is at version
1 - else it will be incremented:

{"update": {"_id": "1"}}
{"upsert": {"vcounter": 0}, "script": "if (ctx._version == '1') {
ctx._source.vcounter = 1 } else { ctx._source.vcounter += 1"}
{"update": {"_id": "1"}}
{"doc": {"field2": 3, "field1": "value1"}, "doc_as_upsert": true}

Can't figure out what the problem is. Not even sure if we can script
against the _version field? The above command always leaves vcounter at 0.

Any pointers would be much appreciated.

G

--
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.