Connecting

edit

This page contains the information you need to connect and use the Client with Elastic Enterprise Search.

On this page

Authentication

edit

This section contains code snippets to show you how to connect to Enterprise Search, App Search, and Workplace Search.

Each service has its own authentication schemes. Enterprise Search uses a basic HTTP authentication with username and password. App Search and Workplace Search also accept a token. Refer to the authentication documentation for App Search and Workplace Search for the supported token types.

Authenticating with Enterprise Search

edit

Enterprise Search supports HTTP basic authentication with a username and password.

You can specify the enterprise-search configuration in the Client initialization:

use Elastic\EnterpriseSearch\Client;

$client = new Client([
    'host' => 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com',
    'enterprise-search' => [
        'username' => '<insert here the username>',
        'password' => '<insert here the password>'
    ]
]);

$enterpriseSearch = $client->enterpriseSearch();

Or pass directly the username and password in the enterpriseSearch() function:

use Elastic\EnterpriseSearch\Client;

$client = new Client([
    'host' => 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com',
]);

$enterpriseSearch = $client->enterpriseSearch([
    'username' => '<insert here the username>',
    'password' => '<insert here the password>'
]);

Authenticating with App Search

edit

Follow the App Search authentication guide to find or create an App Search API key.

The API key is the token that you need to pass in the Client.

You can pass the token in the Client initialization:

use Elastic\EnterpriseSearch\Client;

$client = new Client([
    'host' => 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com',
    'app-search' => [
        'token' => '<insert here the API key>'
    ]
]);

$appSearch = $client->appSearch();

Or pass directly the token in the appSearch() function:

use Elastic\EnterpriseSearch\Client;

$client = new Client([
    'host' => 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com',
]);

$appSearch = $client->appSearch([ 'token' => '<insert here the API key>' ]);

Authenticating with Workplace Search

edit

Workplace Search supports multiple authentication methods:

Workplace Search bearer tokens
edit

Follow the Workplace Search API authentication reference to find or create a bearer token supported by Workplace Search.

You can pass the token in the Client initialization:

use Elastic\EnterpriseSearch\Client;

$client = new Client([
    'host' => 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com',
    'workplace-search' => [
        'token' => '<insert here the access token>'
    ]
]);

$workplaceSearch = $client->workplaceSearch();

Or pass directly the token in the workplaceSearch() function:

use Elastic\EnterpriseSearch\Client;

$client = new Client([
    'host' => 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com',
]);

$workplaceSearch = $client->workplaceSearch([ 'token' => '<insert here the access token>' ]);