Skip to content

Commit 6968658

Browse files
authored
Merge pull request #52 from vbcodeplicity/feature/add-support-for-es8-insert
Add support for insert method for ES8
2 parents b10293f + 320b541 commit 6968658

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/Engine/Elasticsearch/ElasticsearchAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function insert(CollectionNameInterface $collectionName, MappingInterface
7979
->setMethod(self::METHOD_POST)
8080
->setId($data['id'])
8181
->setBody($data)
82-
->execute();
82+
->insert();
8383
}
8484

8585
/**

src/Engine/Elasticsearch/ElasticsearchClient.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ElasticsearchClient
1515
const SEARCH = '_search';
1616
const TIMEOUT = 5;
1717
const METHOD_GET = 'GET';
18+
const INSERT = '_create';
19+
const INSERT_METHOD = 'insert';
1820
const UPDATE = '_update';
1921
const UPDATE_METHOD = 'update';
2022
const REFRESH = '_refresh';
@@ -117,6 +119,19 @@ public function count()
117119

118120
return $this;
119121
}
122+
public function insert()
123+
{
124+
$this->url = ElasticsearchUrlPathBuilder::generateUrl(
125+
$this->url,
126+
$this->index,
127+
$this->indexType,
128+
$this->id,
129+
self::INSERT_METHOD,
130+
$this->version
131+
);
132+
133+
$this->executeCurlRequest();
134+
}
120135

121136
public function update()
122137
{

src/Engine/Elasticsearch/ElasticsearchClientUrlPath.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
class ElasticsearchClientUrlPath
88
{
9+
public static function insert(Url $url, $index, $indexType, $id)
10+
{
11+
return $url->path($index, $indexType, $id);
12+
}
13+
914
public static function update(Url $url, $index, $indexType, $id)
1015
{
1116
return $url->path($index, $indexType, $id, ElasticsearchClient::UPDATE);

src/Engine/Elasticsearch/Version8/ElasticsearchClientUrlPath.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
class ElasticsearchClientUrlPath
99
{
10+
public static function insert(Url $url, $index, $indexType, $id)
11+
{
12+
return $url->path($index, ElasticsearchClient::INSERT, $id);
13+
}
14+
1015
public static function update(Url $url, $index, $indexType, $id)
1116
{
1217
return $url->path($index, ElasticsearchClient::UPDATE, $id);

0 commit comments

Comments
 (0)