PHPackages                             cyber-duck/silverstripe-searchly - 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. cyber-duck/silverstripe-searchly

ActiveSilverstripe-vendormodule[Search &amp; Filtering](/categories/search)

cyber-duck/silverstripe-searchly
================================

Elastic Search integration for SilverStripe

4.4.0(3y ago)216.1k4[2 issues](https://github.com/Cyber-Duck/SilverStripe-Searchly/issues)[1 PRs](https://github.com/Cyber-Duck/SilverStripe-Searchly/pulls)MITPHPPHP &gt;=7.0.0CI failing

Since Feb 19Pushed 10mo ago5 watchersCompare

[ Source](https://github.com/Cyber-Duck/SilverStripe-Searchly)[ Packagist](https://packagist.org/packages/cyber-duck/silverstripe-searchly)[ Docs](https://github.com/cyber-duck/silverstripe-searchly)[ RSS](/packages/cyber-duck-silverstripe-searchly/feed)WikiDiscussions develop Synced yesterday

READMEChangelog (3)Dependencies (2)Versions (15)Used By (0)

SilverStripe Elastic Search
===========================

[](#silverstripe-elastic-search)

This package adds the ability to index DataObjects on any Elastic Search instance running on your local environment, on a server such as AWS, or an Elastic Search service such as Searchly.

[![Latest Stable Version](https://camo.githubusercontent.com/b930853965531768932b79d0246cd132045bad9518ba562948134fc427c3379b/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f73696c7665727374726970652d7365617263686c792f762f737461626c65)](https://packagist.org/packages/cyber-duck/silverstripe-searchly)[![Latest Unstable Version](https://camo.githubusercontent.com/dbe2f5482a012aad537625e1b967858e9437426e947db0cd37758be9307af632/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f73696c7665727374726970652d7365617263686c792f762f756e737461626c65)](https://packagist.org/packages/cyber-duck/silverstripe-searchly)[![Total Downloads](https://camo.githubusercontent.com/542147aef322e654f1e01bc5188ff85ee46fddb1fd72448ca59d762797027290/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f73696c7665727374726970652d7365617263686c792f646f776e6c6f616473)](https://packagist.org/packages/cyber-duck/silverstripe-searchly)[![License](https://camo.githubusercontent.com/abc7f7c56fae8a536e067cab48f0aaf4afe969c7281e8bbcd74688ef5acab41e/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f73696c7665727374726970652d7365617263686c792f6c6963656e7365)](https://packagist.org/packages/cyber-duck/silverstripe-searchly)

Author: [Andrew Mc Cormack](https://github.com/Andrew-Mc-Cormack)

**For SilverStripe 4.\***

- [Installation](#installation)
- [Configuration](#configuration)
- [Setting Your Elastic Search Endpoint](#setting-your-elastic-search-endpoint)
- [Setting DataObject Indexable Fields and Relations](#setting-dataobject-indexable-fields-and-relations)
- [Performing Actions on a Search Index](#performing-actions-on-a-search-index)
    - [createIndex()](#createindexmappings---settings--)
    - [deleteIndex()](#deleteindex)
    - [resetIndex()](#resetindexmappings---settings--)
    - [index()](#indexarray-filters--)
    - [indexRecord()](#indexrecorddataobject-record)
    - [removeRecord()](#removerecorddataobject-record)
    - [Creating an Index Task](#creating-an-index-task)
- [Performing a Search](#performing-a-search)
    - [Configuring Your Search Query](#configuring-your-search-query)
    - [Getting Search Results](#getting-search-results)

Installation
------------

[](#installation)

Add the following to your composer.json file and run /dev/build?flush=all

```
{
    "require": {
        "cyber-duck/silverstripe-searchly": "4.1.*"
    }
}
```

Configuration
-------------

[](#configuration)

Refer to `_config/searchly.yml` for configuration options.

Setting Your Elastic Search Endpoint
------------------------------------

[](#setting-your-elastic-search-endpoint)

Add a SEARCHLY\_BASE\_URI var to your .env file with any valid ES endpoint (AWS, searchly etc)

```
SEARCHLY_BASE_URI="https://site:{api-key}@xyz.searchly.com" -

```

Or for a local docker ES instance or similar

```
SEARCHLY_BASE_URI="http://es:9200"

```

Setting DataObject Indexable Fields and Relations
-------------------------------------------------

[](#setting-dataobject-indexable-fields-and-relations)

Models and their relations can be indexed together as one searchable object. To index fields and their relations you can use searchable\_\* config arrays on your DataObject.

In the example below the relations Tags &amp; ContentBlocks would need their own searchable\_\* config. When indexing, these relationships will be traversed and a nested objects created.

```
private static $searchable_db = [
    'Title',
    'Content'
];

private static $searchable_has_many = [
    'Tags'
];

private static $searchable_many_many = [
    'ContentBlocks'
];
```

Performing Actions on a Search Index
------------------------------------

[](#performing-actions-on-a-search-index)

Creating a search index instance allow you access to functions to change and manipulate a search index such as creating a new one, adding / removing records etc

```
$index = new SearchIndex(
    'pages', // the index name, can be hard coded or better to pull from a .env var
    'pages', // the searchly index _type
    [Page::class] // an array of models to index, can be pages or non pages
);
```

### createIndex($mappings = \[\], $settings = \[\])

[](#createindexmappings---settings--)

Calling this method on your search index instance will build an ES endpoint index. For full configuration for mappings and settings please see the Elastic Search documentation.

```
$mappings = [
    'Created' => [
        'type' => 'date',
    ],
    'LastEdited' => [
        'type' => 'date',
    ],
    'ClassName' => [
        'type' => 'keyword',
    ],
    'Title' => [
        'type' => 'text',
        'boost' => 100,
    ],
    'Link' => [
        'type' => 'text',
        'index' => false,
    ]
];

$settings = [
    'analysis' => [
        'analyzer' => [
            'default' => [
                'type' => 'english',
            ]
        ]
    ]
];

$index->createIndex($mappings, $settings);
```

### deleteIndex()

[](#deleteindex)

This method will completely remove the search index from your ES endpoint

```
$index->deleteIndex();
```

### resetIndex($mappings = \[\], $settings = \[\])

[](#resetindexmappings---settings--)

This method will call deleteIndex() and then call createIndex(). Make sure to pass your mappings and settings configuration as you would for createIndex();

```
$index->resetIndex($mappings, $settings);
```

### index(array $filters = \[\])

[](#indexarray-filters--)

This method will push all the models to the ES endpoint index you specified when creating your search index instance.

In the example below calling index will traverse through all Page and File models, create a JSON representation of them and push them to the ES endpoint index.

```
$index = new SearchIndex(
    'models', // the index name, can be hard coded or better to pull from a .env var
    'models', // the searchly index _type
    [
        Page::class,
        File::class
    ]
);
$index->index();
```

You can also apply filters in case you wish to exclude certain model from the index.

```
$index->index([
    Page::class => [
        'ClassName:not' => ErrorPage::class,
    ],
    File::class => [
        'ClassName:not' => Folder::class,
    ],
]);
```

You can also see all the data sent to the ES endpoint index by calling index() then getRecords(). This will return an array of JSON objects.

```
$index->index([...])->getRecords();
```

### indexRecord(DataObject $record)

[](#indexrecorddataobject-record)

Adds a single data object to the ES endpoint index

```
$index->indexRecord(
    Page::get()->find('ID', 1)
);
```

### removeRecord(DataObject $record)

[](#removerecorddataobject-record)

Removes a single data object from the ES endpoint index

```
$index->removeRecord(
    Page::get()->find('ID', 1)
);
```

### Creating an Index Task

[](#creating-an-index-task)

The easiest way to create your indexes is to create a SilverStripe task and run it to create / rebuild all your indexes

```
use CyberDuck\Searchly\Index\SearchIndex;
use SilverStripe\Assets\File;
use SilverStripe\Dev\BuildTask;

class SearchIndexTask extends BuildTask
{
    protected $enabled = true;

    protected $title = "Searchly Pages index task";

    protected $description = "Indexes all site pages for use in searchly";

    public function run($request)
    {
        $mappings = [
            ... // your configuration
        ];

        $settings = [
            ... // your configuration
        ];

        $index = new SearchIndex(
            'pages', // the index name, can be hard coded or better to pull from a .env var
            'pages', // the searchly index _type
            [Page::class] // an array of models to index, can be pages or non pages
        );
        $index->resetIndex($mappings, $settings);
        $index->index();

        $index = new SearchIndex(
            'files', // the index name, can be hard coded or better to pull from a .env var
            'files', // the searchly index _type
            [File::class] // an array of models to index, can be pages or non pages
        );
        $index->resetIndex($mappings, $settings);
        $index->index();
    }
}
```

If you run into PHP time outs with indexing large numbers of models, you can try to increase the execution time

```
    public function run($request)
    {
        ini_set('max_execution_time', 300);

        $index = new SearchIndex(...
```

Performing a Search
-------------------

[](#performing-a-search)

To perform a search query create a new SearchQuery instance and inject the search term and index name into the constructor.

```
use CyberDuck\Searchly\Index\SearchQuery;

$query = new SearchQuery(
    $term, // the search term
    'pages' // the index name, can be hard coded or better to pull from a .env var
);
```

### Configuring Your Search Query

[](#configuring-your-search-query)

You can control the amount of results returned. Useful for very large data sets.

```
$query->setSize(50);
```

You can also control AND / OR matching

```
$query->setOperator('OR');
```

There is also a custom method for setting analyze\_wildcard config to true / false

```
$query->setWildcard(true);
```

Or you can build your own highly complex configurations for any situation.

```
$query->setConfig('sort', [['Created' => 'desc']]);
$query->setConfig('query', [
    'bool' => [
        'must' => [
            [
                'query_string' => [
                    'query' => '*'.$escapedterm.'*',
                    'analyze_wildcard' => true,
                    'default_operator' => 'OR',
                ]
            ]
        ]
    ]
]);
```

### Getting Search Results

[](#getting-search-results)

To return an array of matched model IDs you can call getIDs()

```
$ids = $query->getIDs();
```

To return an array of matched objects you can call getHits()

```
$objects = $query->getHits();
```

Highlights / matched text can also be returns by calling setHighlight() on the SearchQuery instance and calling getHighlights()

```
$query->setHighlight(true);

$highlights = $query->getHighlights();
```

To return the full ES endpoint response object you can call getResponse() on your query object. Useful for debugging.

```
$response = $query->getResponse();
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~272 days

Recently: every ~316 days

Total

6

Last Release

1261d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c45a99726cc30692bc4821cfc198df1f5de85b1a15f9b66a0bf739acbac0309?d=identicon)[cyber-duck](/maintainers/cyber-duck)

---

Top Contributors

[![samthejarvis](https://avatars.githubusercontent.com/u/1410549?v=4)](https://github.com/samthejarvis "samthejarvis (4 commits)")[![nadge](https://avatars.githubusercontent.com/u/3862793?v=4)](https://github.com/nadge "nadge (2 commits)")[![waiyanhein](https://avatars.githubusercontent.com/u/9372127?v=4)](https://github.com/waiyanhein "waiyanhein (2 commits)")[![cyberduckneil](https://avatars.githubusercontent.com/u/90324469?v=4)](https://github.com/cyberduckneil "cyberduckneil (1 commits)")[![waiyanheincyberduck](https://avatars.githubusercontent.com/u/43062909?v=4)](https://github.com/waiyanheincyberduck "waiyanheincyberduck (1 commits)")[![worzy](https://avatars.githubusercontent.com/u/1092417?v=4)](https://github.com/worzy "worzy (1 commits)")

---

Tags

elasticsearchphpsearchlysearchquery-instancesilverstripesilverstripe-4phpelasticsearchsilverstripeelastic searchsilverstripe 4searchly

### Embed Badge

![Health badge](/badges/cyber-duck-silverstripe-searchly/health.svg)

```
[![Health](https://phpackages.com/badges/cyber-duck-silverstripe-searchly/health.svg)](https://phpackages.com/packages/cyber-duck-silverstripe-searchly)
```

###  Alternatives

[heyday/silverstripe-elastica

Provides Elastic Search integration for SilverStripe DataObjects using Elastica

1136.8k2](/packages/heyday-silverstripe-elastica)

PHPackages © 2026

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