It is a 404 respones when query a index template which is not exist

hi, i am using elasticsearch 6.4.0, when i start my application , i wanna firstly query whether the template exist or not. if it is not exits i will create it .

so when i use the high level client , the code as follows:

        GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest("abc");
        GetIndexTemplatesResponse response =
            highLevelClient.indices().getTemplate(getIndexTemplatesRequest, RequestOptions.DEFAULT);
        if (response.getIndexTemplates().stream().filter(e -> e.getName().equals("abc")).count() != 0)
        {
            //如果template存在则不创建
            runLogger.info("index template {} is exist,no need to create template", "abc");
            return;
        }

so , when it will get the error message like this:

Caused by: org.elasticsearch.ElasticsearchStatusException: Unable to parse response body
        at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1386) ~[elasticsearch-rest-high-level-client-6.4.0.jar:6.4.0]
        at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1269) ~[elasticsearch-rest-high-level-client-6.4.0.jar:6.4.0]
        at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1231) ~[elasticsearch-rest-high-level-client-6.4.0.jar:6.4.0]
        at org.elasticsearch.client.IndicesClient.getTemplate(IndicesClient.java:1228) ~[elasticsearch-rest-high-level-client-6.4.0.jar:6.4.0]

when i first setting the template by curl commad ,it will be ok

so , my question is why this happen when there is no template, or just design to do so.

can anyone give some help..

Could you try with 6.4.2 and if you can still reproduce open an issue in GitHub?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.