Skip to content

Commit

Permalink
Implement updateMappings
Browse files Browse the repository at this point in the history
  • Loading branch information
mmenozzi committed Nov 7, 2024
1 parent e9bf0b0 commit 223012c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

0 comments on commit 223012c

Please sign in to comment.