Skip to content

Commit 9ef242b

Browse files
Oleg Andreyevruflin
Oleg Andreyev
authored andcommitted
Add Version method (#1152)
* adding method to get es version * added functional test for getVersion * using `version_compare` and `ELASTICSEARCH_VERSION`
1 parent a714773 commit 9ef242b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file based on the
1313
- Elastica\QueryBuilder\DSL\Query::geo_distance
1414
- Elastica\Aggregation\GeoCentroid [#1150](https://github.com/ruflin/Elastica/pull/1150)
1515
- [Multi value field](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_multi_values_fields) param for decay function.
16+
- Elastica\Client::getVersion [#1152](https://github.com/ruflin/Elastica/pull/1152)
1617

1718
### Improvements
1819
- Set PHP 7.0 as default development version

env/elasticsearch/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM elasticsearch:2.3.2
22
MAINTAINER Nicolas Ruflin <[email protected]>
33

44
# Dependencies
5+
ENV ELASTICSEARCH_VERSION 2.3.2
56
ENV ES_IMAGE_PLUGIN_VER 1.7.1
67
ENV ES_PLUGIN_BIN /usr/share/elasticsearch/bin/plugin
78

lib/Elastica/Client.php

+20
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class Client
6767
*/
6868
protected $_logger;
6969

70+
/**
71+
* @var string
72+
*/
73+
protected $_version;
74+
7075
/**
7176
* Creates a new Elastica client.
7277
*
@@ -87,6 +92,21 @@ public function __construct(array $config = [], $callback = null, LoggerInterfac
8792
$this->_initConnections();
8893
}
8994

95+
/**
96+
* Get current version
97+
*
98+
* @return string
99+
*/
100+
public function getVersion()
101+
{
102+
if ($this->_version) {
103+
return $this->_version;
104+
}
105+
106+
$data = $this->request('/')->getData();
107+
return $this->_version = $data['version']['number'];
108+
}
109+
90110
/**
91111
* Inits the client connections.
92112
*/

test/lib/Elastica/Test/ClientTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public function testConstruct()
2323
$this->assertCount(1, $client->getConnections());
2424
}
2525

26+
/**
27+
* @group functional
28+
*/
29+
public function testGetVersion()
30+
{
31+
$client = $this->_getClient();
32+
$this->assertNotEmpty($client->getVersion());
33+
$this->assertTrue(version_compare($client->getVersion(), $_SERVER['ELASTICSEARCH_VERSION'], '>='));
34+
}
35+
2636
/**
2737
* @group functional
2838
*/

0 commit comments

Comments
 (0)