# Custom Searchattributes

**URL:** <https://community.temporal.io/t/custom-searchattributes/2943>\
**Category:** Community Support\
**Tags:** search-attributes\
**Created:** [September 16, 2021, 4:40pm UTC](https://community.temporal.io/t/custom-searchattributes/2943 "2021-09-16T16:40:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 16, 2021, 4:40pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/1 "2021-09-16T16:40:48Z")

</div>

1. is it possible to add/change search attributes on a workflow, after it has already started ?

2. We ( java-sdk ) need to add search attributes of the type AAA=xxx on our workflows.  
I don’t see any examples. ( Im not able to understand what HelloSearchAttributes.java is doing )  
We would like to get examples of both writing and searching

3. Once we locate the workflow ( workflowId/runId ), how do we retrieve the value of AAA ?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 16, 2021, 4:48pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/2 "2021-09-16T16:48:13Z")

</div>

1. Yes. Use [Workflow.UpsertSearchAttributes](https://github.com/temporalio/sdk-java/blob/99fa4af639359553abffd0508e561f817f744877/temporal-sdk/src/main/java/io/temporal/workflow/Workflow.java#L1315) API.

2. It starts a workflow passing a few custom search attribute values. Note that each attribute [has to be registered with the service](https://docs.temporal.io/docs/system-tools/tctl#add-new-search-attributes) before SDK can use it.

3. They are available in the response to the DescribeWorkflowExecution API. But if you are doing this, I’m not sure why you are using search attributes instead of a workflow query. The idea for search attributes is that they can be used to list workflows by their values.

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 16, 2021, 4:52pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/3 "2021-09-16T16:52:53Z")

</div>

( Thank you very much Maxim )

Oh. So each search attribute **tag** ( AAA ) has to be added through tctl ?  
So what can be passed to workflow programmatically ? ( **value** xxx for the tag AAA ? )

–sony

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 16, 2021, 5:00pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/4 "2021-09-16T17:00:42Z")

</div>

> Oh. So each search attribute **tag** ( AAA ) has to be added through tctl ?

Yes, you are correct. Custom search attributes correspond to fields in the Elasticsearch schema. So when you register one through tctl the ES schema is updated.

> So what can be passed to workflow programmatically ? ( **value** xxx for the tag AAA ? )

Yes, you pass key-value pair with “AAA” being the key.

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 16, 2021, 5:22pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/5 "2021-09-16T17:22:18Z")

</div>

We do not have an Elastic Search plugin ( Although we have plans to install that in the future )  
Are you saying we cannot attach arbitrary TAG=VALUE s to workflows without installing elastic search ?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 16, 2021, 5:37pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/6 "2021-09-16T17:37:47Z")

</div>

> Are you saying we cannot attach arbitrary TAG=VALUE s to workflows without installing elastic search ?

What is your use case? I think you are trying to achieve something that custom search attributes were not designed for.

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 16, 2021, 5:58pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/7 "2021-09-16T17:58:27Z")

</div>

We have a workflow that processes requests on specific business objects.

Multiple workflows types make multiple changes .  
Our design is to attach business object name to workflow as OUR\_BUSINESS\_OBJECT=objectname as a search attribute… we will also add another search attribute VERSION=versionnumber

( my questions were related to this part )Then from another part of our software, we should be able to query for specific business objects…Our current design is to Temporal search for the specific business object name …once we locate the workflow(workflowid/runid), we will get some data using our queryMethod() on the workflow

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 16, 2021, 6:18pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/8 "2021-09-16T18:18:25Z")

</div>

Have you considered using the “business name” as workflow ID to avoid that lookup step?

> Are you saying we cannot attach arbitrary TAG=VALUE s to workflows without installing elastic search ?

Yes, custom search attributes require Elasticsearch integration.

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 21, 2021, 4:50pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/9 "2021-09-21T16:50:55Z")

</div>

Sorry. I got confused on this again:

> Yes, custom search attributes require Elasticsearch integration.

I ran the default docker-compose.yml ( Cassandra with no ES ). Using this I was successfully able to run io.temporal.samples.hello.HelloSearchAttributes, which uses workflowoptions.setSearchAttributes() and searchAttributes.getIndexedFieldsOrThrow(“CustomStringField”)

So when exactly do you need ElasticSearch ?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 21, 2021, 5:36pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/10 "2021-09-21T17:36:36Z")

</div>

> So when exactly do you need ElasticSearch ?

To perform a search using the “CustomStringField”. You can add attributes to a workflow without ES running, but these attributes cannot be used to filter workflows while listing them.

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 21, 2021, 5:56pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/11 "2021-09-21T17:56:39Z")

</div>

Are you saying :  
String query = …  
ListWorkflowExecutionsRequest req = ListWorkflowExecutionsRequest.newbuilder().setQuery(query).build() ;  
WorkflowService.listWorkflowExecutions(req)

…will fail if the Temporal instance is not backed by an Elastic Search ?  
…although workflowoptions.setSearchAttributes() will succeed

?

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 21, 2021, 5:58pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/12 "2021-09-21T17:58:38Z")

</div>

We are a fairly large organization with a different team running the Temporal instances.  
( Our team is not given access to tctl )  
is there a way for us to check if our temporal instance is backed up by Elastic Search ? ( We have access to teh web ui )

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 21, 2021, 7:25pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/13 "2021-09-21T19:25:34Z")

</div>

I figured this out

```auto
GetSearchAttributesRequest gsa = GetSearchAttributesRequest.newBuilder().build();
      GetSearchAttributesResponse gsares = service.blockingStub().getSearchAttributes(gsa);
      // System.out.println( gsares.toString());

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [September 21, 2021, 7:27pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/14 "2021-09-21T19:27:36Z")

</div>

On the Web-ui side you could click on the “Advanced” button on the top-right side and try to run a query, for example: “ExecutionStatus=2” (to query completed workflows). If it returns results you should have ES capabilities turned on.

---

<div class="post-metadata">

**Author:** ![sonyantony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sonyantony/32/1209_2.png) [@sonyantony](https://community.temporal.io/u/sonyantony)\
**Post date:** [September 21, 2021, 7:30pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/15 "2021-09-21T19:30:26Z")

</div>

Ah. Thanks. very useful.

By teh way… what is the Visibility Archival under Settings

```auto
VISIBILITY ARCHIVAL

Disabled

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [September 21, 2021, 10:40pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/16 "2021-09-21T22:40:45Z")

</div>

> **[Archive Workflow data | Temporal documentation](https://docs.temporal.io/docs/server/archive-data/)**
>
> Temporal's Archival feature is considered experimental and not subject to normal versioning and support policy.

believe the docs might be a little bit outdated as in visibility archival is available (still considered experimental) and works if history archival is enabled.

---

<div class="post-metadata">

**Author:** ![averri](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/averri/32/2742_2.png) [@averri](https://community.temporal.io/u/averri)\
**Post date:** [February 3, 2023, 7:11pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/17 "2023-02-03T19:11:42Z")

</div>

Is it possible to add custom search attributes to Temporal server via its YAML config file, or any other automated way when using Docker Compose?

The sample file I have (`development-sql.yaml`) has a few properties configured:

```yaml
limit.maxIDLength:
  - value: 255
    constraints: {}
system.forceSearchAttributesCacheRefreshOnRead:
  - value: false # Dev setup only. Please don't turn this on in production.
    constraints: {}

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [February 3, 2023, 7:30pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/18 "2023-02-03T19:30:36Z")

</div>

Not via server config (yaml) but you can add them using tctl (with an entry point script for example, see how its done [here](https://github.com/temporalio/docker-builds/blob/main/docker/auto-setup.sh#L293-L306))

---

<div class="post-metadata">

**Author:** ![averri](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/averri/32/2742_2.png) [@averri](https://community.temporal.io/u/averri)\
**Post date:** [February 3, 2023, 7:41pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/19 "2023-02-03T19:41:25Z")

</div>

@tihomir, thanks, I was trying to run the command from inside the Docker container running Temporal, and getting this error, the CLI tool is not connecting to the server:

```auto
bash-5.1$ tctl --auto_confirm admin cluster add-search-attributes --name Username --type Text
Error: Unable to get existing search attributes.
Error Details: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:7233: connect: connection refused"
('export TEMPORAL_CLI_SHOW_STACKS=1' to see stack traces)
bash-5.1$ 

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [February 3, 2023, 8:58pm UTC](https://community.temporal.io/t/custom-searchattributes/2943/20 "2023-02-03T20:58:21Z")

</div>

In that container can you check value of:

`echo $TEMPORAL_CLI_ADDRESS`

If its not set, set it to same value as what you have in your static config for publicClient-\>hotPort.

or set it directly in your tctl command:

`tctl --address <publicClient->hostPort_value> ......`

[Next page](https://community.temporal.io/t/custom-searchattributes/2943.md?page=2)
