# Java prepareGetTemplates Exists call?

**URL:** <https://discuss.elastic.co/t/java-preparegettemplates-exists-call/83917>\
**Category:** Elasticsearch\
**Created:** [April 27, 2017, 5:54pm UTC](https://discuss.elastic.co/t/java-preparegettemplates-exists-call/83917 "2017-04-27T17:54:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![billnbell](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@billnbell](https://discuss.elastic.co/u/billnbell)\
**Post date:** [April 27, 2017, 5:54pm UTC](https://discuss.elastic.co/t/java-preparegettemplates-exists-call/83917/1 "2017-04-27T17:54:56Z")

</div>

Is there a simple way to see if template exists in Java?

client.admin().indices().prepareGetTemplates(TEMPLATE\_NAME).get()

Was thinking more of a prepareExistsTemplates() to do something like HEAD call

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 5, 2017, 9:50am UTC](https://discuss.elastic.co/t/java-preparegettemplates-exists-call/83917/2 "2017-05-05T09:50:28Z")

</div>

This is how [I implemented it](https://github.com/dadoonet/elasticsearch-beyonder/blob/master/src/main/java/fr/pilato/elasticsearch/tools/template/TemplateElasticsearchUpdater.java#L112-L114) so far:

```java
public static boolean isTemplateExist(Client client, String template) {
    return !client.admin().indices().prepareGetTemplates(template).get().getIndexTemplates().isEmpty();
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 2, 2017, 10:02am UTC](https://discuss.elastic.co/t/java-preparegettemplates-exists-call/83917/3 "2017-06-02T10:02:17Z")

</div>

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