Update api

Hi

for using the update query i referred to
http://www.elasticsearch.org/guide/reference/api/update/

eg: And, we can delete the doc if the tags contain blue, or ignore (noop):

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "delete" : ctx.op
= "none"",
"params" : {
"tag" : "blue"
}
}'

I have modified the above query as follows:

curl -XPOST "http://10.118.192.145:9200/test/type1/1/_update" -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "none" : ctx._source.tags += tag",
"params" : {
"tag" : "Orange"
}
}'

I want to check for a tag before adding to it. If the tag exists, do nothing else perform the update to add.

the above query creates a new version for the record but does not add the new tag.

How can i acheive this?

Thanks

Kuwar Sahani

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

Hey,

this works

curl -XPUT localhost:9200/test/type1/1 -d '{
"counter" : 1,
"tags" : ["red"]
}'
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "!ctx._source.tags.contains(tag) ? ctx._source.tags += tag :
ctx.op = "none"",
"params" : {
"tag" : "blue"
}
}'
curl localhost:9200/test/type1/1

this does not

curl -XPUT localhost:9200/test/type1/1 -d '{
"counter" : 1,
"tags" : ["red"]
}'
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "none" :
ctx._source.tags += tag ",
"params" : {
"tag" : "blue"
}
}'
curl localhost:9200/test/type1/1

looks like a bug, I need to check that further, in the meantime try the
first solution...

--Alex

On Mon, Apr 15, 2013 at 11:30 AM, kuwar sahani kuwarsahani@gmail.comwrote:

Hi

for using the update query i referred to
http://www.elasticsearch.org/guide/reference/api/update/

eg: And, we can delete the doc if the tags contain blue, or ignore (noop):

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "delete" :
ctx.op = "none"",
"params" : {
"tag" : "blue"
}
}'

I have modified the above query as follows:

curl -XPOST "http://10.118.192.145:9200/test/type1/1/_update" -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "none" : ctx._source.tags += tag",
"params" : {
"tag" : "Orange"
}
}'

I want to check for a tag before adding to it. If the tag exists, do nothing else perform the update to add.

the above query creates a new version for the record but does not add the new tag.

How can i acheive this?

Thanks

Kuwar Sahani

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

--
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!!
On Monday, 15 April 2013 15:33:47 UTC+5:30, Alexander Reelsen wrote:

Hey,

this works

curl -XPUT localhost:9200/test/type1/1 -d '{
"counter" : 1,
"tags" : ["red"]
}'
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "!ctx._source.tags.contains(tag) ? ctx._source.tags += tag
: ctx.op = "none"",
"params" : {
"tag" : "blue"
}
}'
curl localhost:9200/test/type1/1

this does not

curl -XPUT localhost:9200/test/type1/1 -d '{
"counter" : 1,
"tags" : ["red"]
}'
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "none" :
ctx._source.tags += tag ",
"params" : {
"tag" : "blue"
}
}'
curl localhost:9200/test/type1/1

looks like a bug, I need to check that further, in the meantime try the
first solution...

--Alex

On Mon, Apr 15, 2013 at 11:30 AM, kuwar sahani <kuwar...@gmail.com<javascript:>

wrote:

Hi

for using the update query i referred to
http://www.elasticsearch.org/guide/reference/api/update/

eg: And, we can delete the doc if the tags contain blue, or ignore (noop):

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "ctx._source.tags.contains(tag) ? ctx.op = "delete" :
ctx.op = "none"",
"params" : {
"tag" : "blue"
}
}'

I have modified the above query as follows:

curl -XPOST "http://10.118.192.145:9200/test/type1/1/_update" -d '{

"script" : "ctx._source.tags.contains(tag) ? ctx.op = "none" : ctx._source.tags += tag",
"params" : {
"tag" : "Orange"
}
}'

I want to check for a tag before adding to it. If the tag exists, do nothing else perform the update to add.

the above query creates a new version for the record but does not add the new tag.

How can i acheive this?

Thanks

Kuwar Sahani

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

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