@SuppressWarnings("nls") // Do beans need escaping or will that be done 'automatically'. Test it. Strings do, but probably only quotes?
    private Client lookupClient(String orgId, String clientId, String version) {
        String query = "{" +
                "  \"query\": {" +
                "        \"bool\": {" +
                "            \"filter\": [{" +
                "                    \"term\": {" +
                "                        \"organizationId\": \"{{organizationId}}\" " + // orgId
                "                    }" +
                "          }," +
                "          {" +
                "                    \"term\": {" +
                "                        \"clientId\": \"{{clientId}}\" " + // clientId
                "                    }" +
                "          }," +
                "          {" +
                "                    \"term\": {" +
                "                        \"version\": \"{{version}}\" " + // version
                "          }" +
                "      }" +
                "            ]" +
                "    }" +
                "  }" +
                "}";

        SearchTemplateRequest searchTemplateRequest = new SearchTemplateRequest();
        searchTemplateRequest.setRequest(new SearchRequest(getIndexPrefixWithJoiner() + EsConstants.INDEX_CLIENTS));
        searchTemplateRequest.setScriptType(ScriptType.INLINE);
        searchTemplateRequest.setScript(query);

        Map<String, Object> scriptParams = new HashMap<>();
        scriptParams.put("organizationId", orgId);
        scriptParams.put("clientId", clientId);
        scriptParams.put("version", version);

        searchTemplateRequest.setScriptParams(scriptParams);

        Client client;
        try {
            SearchTemplateResponse response = getClient().searchTemplate(searchTemplateRequest, RequestOptions.DEFAULT);
            SearchResponse searchResponse = response.getResponse();
            SearchHits hits = searchResponse.getHits();

            if (hits.getTotalHits().value == 0) {
                throw new IOException();
            }
            String sourceAsString = response.getResponse().getHits().getAt(0).getSourceAsString();
            client = JSON_MAPPER.readValue(sourceAsString, Client.class);

        } catch (IOException e) {
            throw new ClientNotFoundException(Messages.i18n.format("EsRegistry.ClientNotFound"), e);  //$NON-NLS-1$
        }

        return client;
    }
Searches for a client by its orgid:clientId:version and returns it.
@param orgId the organization id
@param clientId the client id
@param version the version
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsRegistry.java