Is there a easy way do query task or process?

I think camunda not yet provide a good solution for query task or process.
If i need query task in multile process. I must use a cycle to do it.
Just like below code.

    public Set<ApplicationApprovalTask> getTheApplicationApprovalTask(Set<String> processInstanceIds, Long userId, PageAndSize pageAndSize) {
        Set<ApplicationApprovalTask> tasks = new HashSet<>(16);
        User user = userService.getUserIfNotExistsThenThrowException(userId);

        processInstanceIds.forEach(o -> {
            Optional<Set<Task>> result  = getApplicationApprovalTask(user, o);
        return null;

    private Optional<Set<Task>> getApplicationApprovalTask(User user, String processInstanceId) {
        List<Task> tasks = taskService
                .taskDescriptionLike(BaseSignUpProjectProcessConstants.APPLICATION_APPROVAL_TASK_PREFIX + "%")

        Department department = user.getDepartmentOfJoined();
        boolean emptyResult = tasks == null || tasks.isEmpty();

        if (  emptyResult && department != null ) {
            tasks = taskService
                    .taskDefinitionKeyLike(BaseSignUpProjectProcessConstants.APPLICATION_APPROVAL_TASK_PREFIX + "%")

            if (tasks == null || tasks.isEmpty()) {
                return  Optional.empty();
            }else {
                return Optional.of( new HashSet<>(tasks));
        }else {
            return Optional.empty();

Actully this is a stupid implementation. I want a query tool that can be easly to do query just like use sql to query it.

Consider using a business key instead of a processInstanceId and you’ll be able to make a query like this

List<Task> list = taskService.createTaskQuery()
    .processInstanceBusinessKeyIn("someKey", "someOtherKey")