Updating document with script

I am attempting to update some documents with the update_by_query API and ES scripting.

sample documents:
doc = { "name" : "Today"}
doc = { "name" : "Today", "tag": ["yellow", "red"]}
doc = { "name" : "Today", "tag": ["red"]}

I want to add to all of my documents the tag "yellow", some of the documents do not have the field "tag" some do. Some have "yellow" already in the "tag" field, some do not.

So I want to make a query that searches all documents that do not have "yellow" in the field "tag" like this:

    "query": {
        "bool": {
            "must_not": {
                "match": {"tag": "yellow"}
            }
        }

But if I execute a script like what is below it would also not create the field "tag" in documents that don't already have it.

{
    "script": {
        "inline": "ctx._source.tags += tag",
        "params": {
            "tag": "yellow"
        },
        "query": {
            "bool": {
                "must_not": {
                    "match": {"tag": "yellow"}
                }
            }
        }
    }
}

Is there a way to have some script that does something like this (this is psedocode in python):

if "tag" not in source:
    source["tag"] = ["yellow"]
elif "yellow" not in source["tag"]:
    source["tag"] += "yellow"

try sth like (granted you use groovy)

if (ctx._source.tag && !ctx._source.tag.contains('yellow')) { ctx._source.tag.add('yellow') } else { ctx._source.tag = ['yellow']}