# Can a Java program operate on multiple versions of elasticsearch?

**URL:** <https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265>\
**Category:** Elasticsearch\
**Created:** [November 11, 2019, 2:59am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265 "2019-11-11T02:59:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjun1995](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanjun1995/32/65810_2.png) [@sanjun1995](https://discuss.elastic.co/u/sanjun1995)\
**Post date:** [November 11, 2019, 2:59am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/1 "2019-11-11T02:59:16Z")

</div>

I need to develop an es automation tool.  
Our company's es cluster has multiple versions.  
I found that many clients require the corresponding ES version.  
Currently I can only think of Java indirectly using the curl and http tools to operate the ES.  
Such as "curl -XGET [http://localhost:9200/\_snapshot/test\_backup/\_all?pretty](http://localhost:9200/_snapshot/test_backup/_all?pretty)".  
Automated tools designed in this way can operate all versions of ES.

I hope some experts can help me and provide some suggestions. Thank you.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [November 11, 2019, 4:12am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/2 "2019-11-11T04:12:14Z")

</div>

Hi @sanjun1995,

I don't use Java but Python and we have a similar case, so maybe my solution can also apply to your case. In my company we have different version of elastic [2, 5, 6] and for that we installed the different versions of the elastic library making call for the specific connection with the related elastic lib.  
The syntax in library don't change so much between version so it will have a small impact on your code.

---

<div class="post-metadata">

**Author:** ![sanjun1995](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanjun1995/32/65810_2.png) [@sanjun1995](https://discuss.elastic.co/u/sanjun1995)\
**Post date:** [November 11, 2019, 7:21am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/3 "2019-11-11T07:21:13Z")

</div>

> [@gabriel\_tessier](#):
>
> we installed the different versions of the elastic library making call for the specific connection with the related elastic lib.

Thanks for your advice.  
In this case, does the call need to bring specific version information?  
I hope this is transparent.

---

<div class="post-metadata">

**Author:** ![sanjun1995](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanjun1995/32/65810_2.png) [@sanjun1995](https://discuss.elastic.co/u/sanjun1995)\
**Post date:** [November 11, 2019, 7:22am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/4 "2019-11-11T07:22:44Z")

</div>

Do you choose different libraries to call based on the version information of the cluster?

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [November 11, 2019, 8:45am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/5 "2019-11-11T08:45:16Z")

</div>

> [@sanjun1995](#):
>
> Do you choose different libraries to call based on the version information of the cluster?

As I understand my case is different as I already know the endpoint and the version so I don't need to guess. For example 172.16.10.x is version 2.x and it will not change, at least this year.  
If you don't know which version is running as far as I know the GET 123.0.0.1:9200/ always return the version of elastic. This one didn't change from version 0.x You can get it from here and load the correct lib version.  
In python you can prefix your import and install in different directory so it make very easy to have different versions of a library. For Java it's maybe more hard.

---

<div class="post-metadata">

**Author:** ![sanjun1995](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanjun1995/32/65810_2.png) [@sanjun1995](https://discuss.elastic.co/u/sanjun1995)\
**Post date:** [November 11, 2019, 8:58am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/6 "2019-11-11T08:58:49Z")

</div>

> [@gabriel\_tessier](#):
>
> As I understand my case is different as I already know the endpoint and the version so I don't need to guess. For example 172.16.10.x is version 2.x and it will not change, at least this year.  
> If you don't know which version is running as far as I know the GET 123.0.0.1:9200/ always return the version of elastic. This one didn't change from version 0.x You can get it from here and load the correct lib version.  
> In python you can prefix your import and install in different directory so it make very easy to have different versions of a library. For Java it's maybe more hard.

Wow, your idea is very good, I am afraid that multiple libraries in Java will cause dependency conflicts.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [November 11, 2019, 9:06am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/7 "2019-11-11T09:06:46Z")

</div>

in python there's virtual environment that make think more easy to use.

[https://virtualenv.pypa.io/en/latest/](https://virtualenv.pypa.io/en/latest/)

---

<div class="post-metadata">

**Author:** ![sanjun1995](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanjun1995/32/65810_2.png) [@sanjun1995](https://discuss.elastic.co/u/sanjun1995)\
**Post date:** [November 11, 2019, 9:20am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/9 "2019-11-11T09:20:12Z")

</div>

Thank you for your help 💞

---

<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:** [December 9, 2019, 9:20am UTC](https://discuss.elastic.co/t/can-a-java-program-operate-on-multiple-versions-of-elasticsearch/207265/10 "2019-12-09T09:20:13Z")

</div>

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