diff --git a/src/Client.php b/src/Client.php index 2ebade5..d6a723a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -225,6 +225,14 @@ public function updateIndexSettings(string $target, array $body = null): Promise return $this->doJsonRequest($method, $uri, $body); } + public function updateMappings(string $target, array $body = null): Promise + { + $method = 'PUT'; + $uri = implode('/', [$this->baseUri, urlencode($target), '_mappings']); + + return $this->doJsonRequest($method, $uri, $body); + } + private function createJsonRequest(string $method, string $uri, string $body = null): Request { $request = new Request($uri, $method); diff --git a/tests/Integration/ClientTest.php b/tests/Integration/ClientTest.php index 2c08f1f..03d33b9 100644 --- a/tests/Integration/ClientTest.php +++ b/tests/Integration/ClientTest.php @@ -370,4 +370,18 @@ public function testUpdateIndexSettings(): void $response = Promise\wait($this->client->getIndex(self::TEST_INDEX)); $this->assertEquals(2000, $response[self::TEST_INDEX]['settings']['index']['mapping']['total_fields']['limit']); } + + public function testUpdateMappings(): void + { + Promise\wait($this->client->createIndex(self::TEST_INDEX)); + + $response = Promise\wait( + $this->client->updateMappings(self::TEST_INDEX, ['properties' => ['testField' => ['type' => 'text']]]) + ); + + $this->assertIsArray($response); + $this->assertTrue($response['acknowledged']); + $response = Promise\wait($this->client->getIndex(self::TEST_INDEX)); + $this->assertEquals('text', $response[self::TEST_INDEX]['mappings']['properties']['testField']['type']); + } }