Documentation around search workflows/executions (java-sdk)


I am looking for documentation, java doc and usage around workflow search - describe/list/query workflows/workflowExecutions.
for example queryWorkflow, QueryWorkflowRequest…
It would be very useful, if you can add a section in here with pointers to further docs like java doc and usage.

Thanks in Advance!

1 Like

Any help is appreciated.
Basically using java-sdk, i want to see workflow execution history.
Are are they any doc/code samples around this?


We don’t have specific Java samples at this point. List queries are done through gRPC stub:

    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(...);
     ListOpenWorkflowExecutionsRequest listRequest =
      ListOpenWorkflowExecutionsResponse listResponse =

The service supports all the other gRPC APIs like DescribeWorkflowExecution.

For queries see HelloQuery sample.

Thank you for responding.

I am trying to use

            ListWorkflowExecutionsRequest request = ListWorkflowExecutionsRequest
                        ListWorkflowExecutionsResponse response = service.blockingStub()

I am testing locally against the docker container (docker-compose-mysql.yml)

It gives the response INVALID_ARGUMENT: Operation not support. Please use on ElasticSearch
I am using mysql without elastic search.
I would like to know which api supports getting workflows given a workflowType and a namespace, in this case(no elastic search).

Only ListOpenWorkflowExecutions and ListClosedWorkflowExecutions APIs are supported without ElasticSearch.

Is there a way to get only open/closed workflow executions for a given workflowType ?

Yes, both ListOpenWorkflowExecutions and ListClosedWorkflowExecutions accept WorkflowTypeFilter as a parameter.

Cool that was helpful.

1 Like

Further questions:

  1. Please confirm
    listOpenWorkflowExecutions - returns all which has status Running
    listClosedWorkflowExecutions - returns all which has status != Running

io.temporal.api.enums.v1.WorkflowExecutionStatus is my reference

  1. For listClosedWorkflowExecutions, could we further filter by status ?
  1. Yes, you are correct.
  2. I believe you should be able to. But please test this as not all filter combinations are supported.

Thank you for clarifying

Hi Maxim

I am trying to add custom queryMethod to a workflow.
Which API (sdk-java) can i use to call this queryMethod on closed and open workflows?


The standard way to call the query method on the stub created through the Client. There is no API difference when querying closed and open workflows. See HelloQuery sample as a reference.

For listClosedWorkflowExecutions/describe/getWorkflowExecutionHistory, this is how I called the apis

WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
 WorkflowExecution execution = WorkflowExecution
    GetWorkflowExecutionHistoryRequest request = GetWorkflowExecutionHistoryRequest
    GetWorkflowExecutionHistoryResponse response = service.blockingStub()

Is there a similar way to call the query method ?

I’m not sure I understand your question. Is the approach from the HelloQuery not working for you?

i want to know how to call the custom query method if i have just the workflowId and runId

MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, <workflowId>);

yes thats what is given in HelloQuery sample.

I wanted to know if there is a way to call the custom query method if i have just the workflowId and runId

Do you mean when you don’t have the class definition? You can use an untyped stub:

  WorkflowStub workflow = Workflow.newUntypedWorkflowStub(
      "<workflowId>",  Optional.of("<runId>"), Optional.empty());
  <ResultClass> result =  workflow.query("<queryType>", <ResultClass>.class);

Yes. Thanku.
That worked fine on workflows which are running.
But on completed workflows it throws error and I had reported it sometime back - Custom query on a terminated workflow returns error - #2 by maxim

Any updates on the issue?