PHPackages                             elastic/site-search-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. elastic/site-search-php

Abandoned → [elastic/site-search](/?search=elastic%2Fsite-search)Library[Search &amp; Filtering](/categories/search)

elastic/site-search-php
=======================

Elastic Site Search Official PHP Client

1.0.5(2y ago)690912[1 issues](https://github.com/elastic/site-search-php/issues)Apache-2.0PHPPHP ^5.6|^7.0|^8.0CI failing

Since Jul 26Pushed 1y ago20 watchersCompare

[ Source](https://github.com/elastic/site-search-php)[ Packagist](https://packagist.org/packages/elastic/site-search-php)[ Docs](https://github.com/elastic/site-search-php)[ RSS](/packages/elastic-site-search-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (7)Versions (8)Used By (0)

[![Elastic Site Search Logo](https://github.com/elastic/site-search-php/raw/master/logo-site-search.png?raw=true)](https://github.com/elastic/site-search-php/blob/master/logo-site-search.png?raw=true)

 [![](https://camo.githubusercontent.com/41e3459515ab450c5e53a505f32663e578e2a353aaedfd13c5f2aa8c3cebe769/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656c61737469632f736974652d736561726368)](https://camo.githubusercontent.com/41e3459515ab450c5e53a505f32663e578e2a353aaedfd13c5f2aa8c3cebe769/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656c61737469632f736974652d736561726368) [![GitHub release](https://camo.githubusercontent.com/ecb37881e4697605f53a12313f5fac75e66dad83c1fc934c87d232dbf753a64b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f656c61737469632f736974652d7365617263682d7068702f616c6c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/elastic/site-search-php/releases) [![CircleCI build](https://camo.githubusercontent.com/c2ba92787270d57d93c3ebe1de04b15d9d2dc10a9046f4a30fc7881aa6e9ed23/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f6275696c642f6769746875622f656c61737469632f736974652d7365617263682d7068702f6d6173746572)](https://circleci.com/gh/elastic/site-search-php) [![Dependencies status](https://camo.githubusercontent.com/7400561be61f3fa7930b19a800b6013628cbfc0fd52133cbcaa0fd2c44bd4a0a/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f656c61737469632f736974652d7365617263682d706870)](https://camo.githubusercontent.com/7400561be61f3fa7930b19a800b6013628cbfc0fd52133cbcaa0fd2c44bd4a0a/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f656c61737469632f736974652d7365617263682d706870)

> A first-party PHP client for the [Elastic Site Search API](https://swiftype.com/documentation/site-search/overview).

Contents
--------

[](#contents)

- [Getting started](#getting-started-)
- [Usage](#usage)
- [Development](#development)
- [FAQ](#faq-)
- [Contribute](#contribute-)
- [License](#license-)

---

Getting started 🐣
-----------------

[](#getting-started-)

Using this client assumes that you have already created a Site Search account on .

You can install the client in your project by using composer:

```
composer require elastic/site-search
```

Usage
-----

[](#usage)

### Configuring the client

[](#configuring-the-client)

#### Basic client instantiation

[](#basic-client-instantiation)

To instantiate a new client you can use `\Elastic\SiteSearch\Client\ClientBuilder`:

```
  $apiKey        = 'XXXXXXXXXXXX';
  $clientBuilder = \Elastic\SiteSearch\Client\ClientBuilder::create($apiKey);

  $client = $clientBuilder->build();
```

**Notes:**

- The resulting client will be of type `\Elastic\SiteSearch\Client\Client`
- You can find the API endpoint and your API key URL in your Site Search account: .
- The Site Search PHP client does not support authentication through Engine Key as described in the [documentation](https://swiftype.com/documentation/site-search/overview#authentication).

### Basic usage

[](#basic-usage)

#### Retrieve or create an engine

[](#retrieve-or-create-an-engine)

Most methods of the API require that you have access to an Engine.

To check if an Engine exists and retrieve its configuration, you can use the `Client::getEngine` method :

```
  $engine = $client->getEngine('my-engine');
```

If the Engine does not exists yet, you can create it by using the `Client::createEngine` method :

```
  $engine = $client->createEngine('my-engine', 'en');
```

The second parameter (`$language`) is optional or can be set to null. Then the Engine will be created using the `universal` language. The list of supported language is available here :

#### Document types

[](#document-types)

When using Site Search every document has an associated DocumentType.

You can list available document types in an engine by using the `Client::listDocumentTypes` method:

```
  $documentTypes = $client->listDocumentTypes('my-engine');
```

In order to index documents you need to create at least one DocumentType in your engine. This can be done by using the Client::createDocumentType` method:

```
  $documentType = $client->createDocumentType('my-engine', 'my-document-type');

```

#### Index some documents

[](#index-some-documents)

In order to index some documents in the Engine you can use the `Client::createOrUpdateDocuments` method:

```
    $documents = [
      [
        'external_id' => 'first-document',
        'fields'      => [
          ['name' => 'title', 'value' => 'First document title', 'type' => 'string'],
          ['name' => 'content', 'value' => 'Text for the first document.', 'type' => 'string'],
        ]
      ],
      [
        'external_id' => 'other-document',
        'fields'      => [
          ['name' => 'title', 'value' => 'Other document title', 'type' => 'string'],
          ['name' => 'content', 'value' => 'Text for the other document.', 'type' => 'string'],
        ]
      ],
    ];

    $indexingResults = $client->createOrUpdateDocuments('my-engine', 'my-document-type', $documents);
```

**Notes:**

- The `$indexingResults` array will contains the result of the indexation of each documents. You should always check the content of the result.
- A full list of available field types and associated use cases is available here:
- Full documentation for the endpoint and other method available to index documents is available here: .

#### Search

[](#search)

In order to search in your Engine you can use the `Client::search` method :

```
    $searchResponse = $client->search('my-engine', 'fulltext search query');
```

An optional `$searchRequestParams` can be used to pass additional parameters to the Search API endpoint (pagination, filters, facets, ...):

```
    $searchParams = ['per_page' => 10, 'page' => 2];
    $searchResponse = $client->search('my-engine', 'fulltext search query', $searchParams);
```

Allowed params are :

Param nameDescriptionDocumentation URL`per_page` and `page`Control pagination. `document_types`Searched document types.`filters`Search filters`facets`Search facets.`boosts`Search boosts. `fetch_fields`Fields returned by the search.`search_fields`Field (weighted) used by the search.`highlight_fields`Field highlighting configuration.`sort_field` and `sort_direction`Result sort order configuration`spelling`Control over the spellchecker behavior.### Clients methods

[](#clients-methods)

MethodDescriptionDocumentation**`asyncCreateOrUpdateDocuments`**Async bulk creation or update of documents in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documents` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#bulk_indexing)**`createDocument`**Create a new document in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documentExternalId` (required)
 - `$documentFields` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#add-document)**`createDocumentType`**Create a new document type in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeName` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#add-documenttype)**`createDocuments`**Bulk creation of documents in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documents` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#bulk_create)**`createEngine`**Create a new API based engine.

 **Parameters :**
 - `$engineName` (required)
 - `$engineLanguage`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/engines#create)**`createOrUpdateDocument`**Create or update a document in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documentExternalId` (required)
 - `$documentFields` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#add-document)**`createOrUpdateDocuments`**Bulk creation or update of documents in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documents` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#bulk_create_or_update_verbose)**`deleteDocument`**Delete a document from the engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$externalId` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#delete-external-id)**`deleteDocumentType`**Delete a document type by id.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#documenttypes-delete)**`deleteDocuments`**Bulk delete of documents in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documents` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#bulk_destroy)**`deleteEngine`**Delete an engine by name.

 **Parameters :**
 - `$engineName` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/engines#destroy)**`getAutoselectsCountAnalyticsDocumentType`**Retrieve number of autoselects (number of clicked results in the autocomplete) per day over a period for a document type.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$startDate`
 - `$endDate`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#autoselects)**`getAutoselectsCountAnalyticsEngine`**Retrieve number of autoselects (number of clicked results in the autocomplete) per day over a period for an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$startDate`
 - `$endDate`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#autoselects)**`getClicksCountAnalyticsDocumentType`**Retrieve number of clicks per day over a period for a document type.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$startDate`
 - `$endDate`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#clicks)**`getClicksCountAnalyticsEngine`**Retrieve number of clicks per day over a period for an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$startDate`
 - `$endDate`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#clicks)**`getDocument`**Retrieve a document from the engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$externalId` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#document-single)**`getDocumentReceipts`**Check the status of document receipts issued by aync bulk indexing.

 **Parameters :**
 - `$receiptIds` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#bulk_create_or_update_verbose)**`getDocumentType`**Get a document type by id.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#documenttypes-single)**`getEngine`**Retrieves an engine by name.

 **Parameters :**
 - `$engineName` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/engines#one-engine)**`getSearchCountAnalyticsDocumentType`**Get the number of searches per day for an document type.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$startDate`
 - `$endDate`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#searches)**`getSearchCountAnalyticsEngine`**Get the number of searches per day for an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$startDate`
 - `$endDate`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#searches)**`getTopNoResultQueriesAnalyticsDocumentType`**Retrieve top queries with no result and usage count over a period for a document type.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$startDate`
 - `$endDate`
 - `$currentPage`
 - `$pageSize`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#top_no_result_queries)**`getTopNoResultQueriesAnalyticsEngine`**Retrieve top queries with no result and usage count over a period for an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$startDate`
 - `$endDate`
 - `$currentPage`
 - `$pageSize`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#top_no_result_queries)**`getTopQueriesAnalyticsDocumentType`**Retrieve top queries and usage count over a period for a document type.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$startDate`
 - `$endDate`
 - `$currentPage`
 - `$pageSize`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#top_queries)**`getTopQueriesAnalyticsEngine`**Retrieve top queries and usage count over a period for an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$startDate`
 - `$endDate`
 - `$currentPage`
 - `$pageSize`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#top_queries)**`listDocumentTypes`**List all document types for an engine.

 **Parameters :**
 - `$engineName` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#documenttypes-all)**`listDocuments`**List all documents in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#document-all)**`listEngines`**Retrieves all engines with optional pagination support.

 **Parameters :**
 - `$currentPage`
 - `$pageSize`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/engines#list)**`logClickthrough`**Record a clickthrough for a particular result.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documentId` (required)
 - `$queryText` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/analytics#recording_clickthroughs)**`search`**Run a search request accross an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$queryText` (required)
 - `$searchRequestParams`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/searching)**`suggest`**Run an autocomplete search request accross an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$queryText` (required)
 - `$searchRequestParams`
[Endpoint Documentation](https://swiftype.com/documentation/site-search/autocomplete)**`updateDocumentFields`**Update fields of a document.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$externalId` (required)
 - `$fields` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#updating_fields)**`updateDocuments`**Bulk update of documents in an engine.

 **Parameters :**
 - `$engineName` (required)
 - `$documentTypeId` (required)
 - `$documents` (required)
[Endpoint Documentation](https://swiftype.com/documentation/site-search/indexing#bulk_update)Development
-----------

[](#development)

Code for the endpoints is generated automatically using a custom version of [OpenAPI Generator](https://github.com/openapitools/openapi-generator).

To regenerate endpoints, use the docker laucher packaged in `vendor/bin`:

```
./vendor/bin/elastic-openapi-codegen.sh
```

The custom generator will be built and launched using the following Open API spec file : `resources/api/api-spec.yml`.

You can then commit and PR the modified api-spec file and your endpoints code files.

The client class and readme may be changed in some cases. Do not forget to include them in your commit!

FAQ 🔮
-----

[](#faq-)

### Where do I report issues with the client?

[](#where-do-i-report-issues-with-the-client)

If something is not working as expected, please open an [issue](https://github.com/elastic/site-search-php/issues/new).

### Where can I find the full API documentation ?

[](#where-can-i-find-the-full-api-documentation-)

Your best bet is to read the [documentation](https://swiftype.com/documentation/site-search).

### Where else can I go to get help?

[](#where-else-can-i-go-to-get-help)

You can checkout the [Elastic community discuss forums](https://discuss.elastic.co/c/site-search).

Contribute 🚀
------------

[](#contribute-)

We welcome contributors to the project. Before you begin, a couple notes...

- Before opening a pull request, please create an issue to [discuss the scope of your proposal](https://github.com/elastic/site-search-php/issues).
- Please write simple code and concise documentation, when appropriate.

License 📗
---------

[](#license-)

[Apache 2.0](https://github.com/elastic/site-search-php/blob/master/LICENSE) © [Elastic](https://github.com/elastic)

Thank you to all the [contributors](https://github.com/elastic/site-search-php/graphs/contributors)!

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance24

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 74.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~338 days

Recently: every ~411 days

Total

6

Last Release

794d ago

PHP version history (2 changes)1.0.0PHP ^5.6|^7.0

1.0.3PHP ^5.6|^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/75c7c511421feb14316a01d29a7566bd4fdd97147b5a4f3faa5a065f9d0a0193?d=identicon)[ezimuel](/maintainers/ezimuel)

![](https://www.gravatar.com/avatar/ba68169b385c1d03c63650369b86685236583f1c8c223f840d54b6582922b911?d=identicon)[afoucret](/maintainers/afoucret)

![](https://www.gravatar.com/avatar/f887e605035c0c2b5ae9b8affd560079327e995aa92f08e2102c468359121e97?d=identicon)[JasonStoltz](/maintainers/JasonStoltz)

---

Top Contributors

[![afoucret](https://avatars.githubusercontent.com/u/529238?v=4)](https://github.com/afoucret "afoucret (20 commits)")[![goodroot](https://avatars.githubusercontent.com/u/9484709?v=4)](https://github.com/goodroot "goodroot (3 commits)")[![JasonStoltz](https://avatars.githubusercontent.com/u/1427475?v=4)](https://github.com/JasonStoltz "JasonStoltz (2 commits)")[![aznick](https://avatars.githubusercontent.com/u/4032882?v=4)](https://github.com/aznick "aznick (1 commits)")[![tutelaris](https://avatars.githubusercontent.com/u/5709507?v=4)](https://github.com/tutelaris "tutelaris (1 commits)")

---

Tags

api-clientelasticelastic-site-searchphpsearchswiftypephpclientsearchelastic

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/elastic-site-search-php/health.svg)

```
[![Health](https://phpackages.com/badges/elastic-site-search-php/health.svg)](https://phpackages.com/packages/elastic-site-search-php)
```

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M943](/packages/elasticsearch-elasticsearch)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)[babenkoivan/elastic-adapter

Adapter for official PHP Elasticsearch client

404.0M9](/packages/babenkoivan-elastic-adapter)[elastic/enterprise-search

Enterprise Search official PHP client

25617.7k9](/packages/elastic-enterprise-search)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
