BadSearchAttributes: search attribute xxxx is not defined

I using Upsert Search Attributes during Workflow Execution and got a weird error:

  1. If I use the example custom attribute as below, the workflow work well
    attributes := map[string]interface{}{
    “CustomIntField”: 1,
    “CustomBoolField”: true,
    }
  2. But when I change the attribute keys as below
    attributes := map[string]interface{}{
    “CustomKeywordField11111”: “test”,
    }
    It raise error
"BadSearchAttributes: search attribute CustomKeywordField11111 is not defined"

Does anybody know the reason?

Hello @Van_Tam_Nguy_n ,

To use search attributes from your workflow code you have to define them first. With tctl you can add, list or remove search attributes.

Are you using docker compose to run Temporal Server? if so, docker-compose uses the auto-setup docker image that creates, among others, the default namespace and custom search attributes

You can read about how auto-setup works here How Temporal Auto-Setup Works

Just to add, the “CustomXYZ” search attributes that the sample is using are added by default to your ES index (see here) as well are added if you dont use advanced visibility, so those do no not have to be registered before running the sample.

If you want to use your custom search attribute (not the default ones) yes as mentioned please add it to your cluster first, for example:

tctl adm cl asa -n CustomKeywordField11111 -t Text

(wait about 10s for cluster ns cache to refresh and then run your sample again.

1 Like

Thanks @antonio.perez @tihomir

@tihomir @antonio.perez I have 1 question:
could we use golang client to add define search attributes instead of command line tool tctl?

works perfectly
e.g.
tctl admin cluster add-search-attributes --name StudentId --type Text