![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/opensearch-project/opensearch-php/ |
- [User Guide](#user-guide) - [Example usage](#example-usage) # User Guide Install this client using Composer into your project `composer req opensearch-project/opensearch-php` ## Example usage ```php <?php require __DIR__ . '/vendor/autoload.php'; $client = (new \OpenSearch\ClientBuilder()) ->setHosts(['https://localhost:9200']) ->setBasicAuthentication('admin', 'admin') // For testing only. Don't store credentials in code. ->setSSLVerification(false) // For testing only. Use certificate for validation ->build(); $indexName = 'test-index-name'; // Print OpenSearch version information on console. var_dump($client->info()); // Create an index with non-default settings. $client->indices()->create([ 'index' => $indexName, 'body' => [ 'settings' => [ 'index' => [ 'number_of_shards' => 4 ] ] ] ]); $client->create([ 'index' => $indexName, 'id' => 1, 'body' => [ 'title' => 'Moneyball', 'director' => 'Bennett Miller', 'year' => 2011 ] ]); // Search for it var_dump( $client->search([ 'index' => $indexName, 'body' => [ 'size' => 5, 'query' => [ 'multi_match' => [ 'query' => 'miller', 'fields' => ['title^2', 'director'] ] ] ] ]) ); // Delete a single document $client->delete([ 'index' => $indexName, 'id' => 1, ]); // Delete index $client->indices()->delete([ 'index' => $indexName ]); ```