0

I had a field named 'tags' in my documents, which is of type array, how can I do this:

If a tag is in the field 'tags', then do nothing; else add the tag to 'tags'.

Forgive me that I have no idea with groovy, but I've tried this:

curl -XPOST localhost:9200/file/company/13862/_update?pretty -d '{script:{inline:"ctx._source.tags.contains(tag) ? ctx.op=\"noop\" : ctx._source.tags += tag", params: {tag: 3}}}'

But it turns out the error:

"Failed to compile inline script [ctx._source.tags.contains(tag) ? ctx.op=\"noop\" : ctx._source.tags += tag] using lang [groovy]"

1 Answer 1

0

Try this

{
  "script": {
    "inline": "if(ctx._source.tags.contains(tag)){ ctx.op = \"none\"} else{ ctx._source.tags += tag }",
    "params": {
      "tag": 3
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I'll try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.