{"id":13684526,"url":"https://github.com/cakephp/elastic-search","last_synced_at":"2025-04-04T08:09:57.471Z","repository":{"id":14386535,"uuid":"17096843","full_name":"cakephp/elastic-search","owner":"cakephp","description":"Elastic search datasource for CakePHP","archived":false,"fork":false,"pushed_at":"2024-07-12T14:28:24.000Z","size":961,"stargazers_count":88,"open_issues_count":3,"forks_count":53,"subscribers_count":31,"default_branch":"4.x","last_synced_at":"2024-10-25T11:48:10.108Z","etag":null,"topics":["cakephp","cakephp-plugin","elasticsearch","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cakephp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-22T23:00:27.000Z","updated_at":"2024-10-25T01:46:14.000Z","dependencies_parsed_at":"2024-01-22T07:47:56.983Z","dependency_job_id":"fd394508-d2d1-4642-a851-78fb1f2e47af","html_url":"https://github.com/cakephp/elastic-search","commit_stats":{"total_commits":488,"total_committers":50,"mean_commits":9.76,"dds":0.6762295081967213,"last_synced_commit":"ea9279c803e42191a6d07f3327214c7943ed9e0e"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Felastic-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Felastic-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Felastic-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Felastic-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cakephp","download_url":"https://codeload.github.com/cakephp/elastic-search/tar.gz/refs/heads/4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142074,"owners_count":20890653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cakephp","cakephp-plugin","elasticsearch","php"],"created_at":"2024-08-02T14:00:34.507Z","updated_at":"2025-04-04T08:09:57.452Z","avatar_url":"https://github.com/cakephp.png","language":"PHP","readme":"# Elasticsearch Datasource for CakePHP\n\n![Build Status](https://github.com/cakephp/elastic-search/actions/workflows/ci.yml/badge.svg?branch=master)\n[![Latest Stable Version](https://img.shields.io/github/v/release/cakephp/elastic-search?sort=semver\u0026style=flat-square)](https://packagist.org/packages/cakephp/elastic-search)\n[![Total Downloads](https://img.shields.io/packagist/dt/cakephp/elastic-search?style=flat-square)](https://packagist.org/packages/cakephp/elastic-search/stats)\n[![Code Coverage](https://img.shields.io/coveralls/cakephp/elastic-search/master.svg?style=flat-square)](https://coveralls.io/r/cakephp/elastic-search?branch=master)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n\nUse [Elastic Search](https://www.elastic.co/) as an alternative ORM backend in CakePHP 5.0+.\n\nYou can [find the documentation for the plugin in the Cake Book](https://book.cakephp.org/elasticsearch).\n\n## Installing Elasticsearch via composer\n\nYou can install Elasticsearch into your project using\n[composer](https://getcomposer.org). For existing applications you can add the\nfollowing to your `composer.json` file:\n\n    \"require\": {\n        \"cakephp/elastic-search\": \"^4.0\"\n    }\n\nAnd run `php composer.phar update`\n\n### Versions Table\n\n| Cake\\ElasticSearch                                                 | CakePHP   | ElasticSearch |\n| ---                                                                | ---       | ---           |\n| [1.x](https://github.com/cakephp/elastic-search/tree/1.0)          | 3.0 - 3.5 | 2.x - 5.x     |\n| [2.x](https://github.com/cakephp/elastic-search/tree/2.x)          | 3.6+      | 6.x           |\n| [\u003e3, \u003c3.4.0](https://github.com/cakephp/elastic-search/tree/3.3.0) | 4.0+      | 6.x           |\n| [\u003e=3.4.0](https://github.com/cakephp/elastic-search/tree/3.x)      | 4.0+      | 7.x           |\n| [4.x](https://github.com/cakephp/elastic-search/tree/4.x)          | 5.0+      | 7.x           |\n\nYou are seeing the 3.x version.\n\n## Connecting the Plugin to your Application\n\nAfter installing, you should tell your application to load the plugin:\n\n```php\nuse Cake\\ElasticSearch\\Plugin as ElasticSearchPlugin;\n\nclass Application extends BaseApplication\n{\n    public function bootstrap()\n    {\n        $this-\u003eaddPlugin(ElasticSearchPlugin::class);\n\n        // If you want to disable to automatically configure the Elastic model provider\n        // and FormHelper do the following:\n        // $this-\u003eaddPlugin(ElasticSearchPlugin::class, [ 'bootstrap' =\u003e false ]);\n    }\n}\n```\n\n## Defining a connection\n\nBefore you can do any work with Elasticsearch models, you'll need to define\na connection:\n\n```php\n// in config/app.php\n    'Datasources' =\u003e [\n        // other datasources\n        'elastic' =\u003e [\n            'className' =\u003e 'Cake\\ElasticSearch\\Datasource\\Connection',\n            'driver' =\u003e 'Cake\\ElasticSearch\\Datasource\\Connection',\n            'host' =\u003e '127.0.0.1',\n            'port' =\u003e 9200\n        ],\n    ]\n```\nAs an alternative you could use a link format if you like to use enviroment variables for example.\n\n```php\n// in config/app.php\n    'Datasources' =\u003e [\n        // other datasources\n        'elastic' =\u003e [\n            'url' =\u003e env('ELASTIC_URL', null)\n        ]\n    ]\n\n    // and make sure the folowing env variable is available:\n    // ELASTIC_URL=\"Cake\\ElasticSearch\\Datasource\\Connection://127.0.0.1:9200?driver=Cake\\ElasticSearch\\Datasource\\Connection\"\n```\n\nYou can enable request logging by setting the `log` config option to true. By\ndefault the `debug` Log profile will be used. You can also\ndefine an `elasticsearch` log profile in `Cake\\Log\\Log` to customize where\nElasticsearch query logs will go. Query logging is done at a 'debug' level.\n\n## Getting a Index object\n\nIndex objects are the equivalent of `ORM\\Table` instances in elastic search. You can\nuse the `IndexRegistry` factory to get instances, much like `TableRegistry`:\n\n```php\nuse Cake\\ElasticSearch\\IndexRegistry;\n\n$comments = IndexRegistry::get('Comments');\n```\n\nIf you have loaded the plugin with bootstrap enabled you could load indexes using the model factory in your controllers\n```php\nclass SomeController extends AppController\n{\n    public function initialize()\n    {\n        $this-\u003eloadModel('Comments', 'Elastic');\n    }\n\n    public function index()\n    {\n        $comments = $this-\u003eComments-\u003efind();\n    }\n\n    ...\n```\n\nEach `Index` object needs a correspondent Elasticsearch _index_, just like most of `ORM\\Table` needs a database _table_.\n\nIn the above example, if you have defined a class as `CommentsIndex` and the `IndexRegistry` can find it, the `$comments` will receive a initialized object with inner configurations of connection and index. But if you don't have that class, a default one will be initialized and the index name on Elasticsearch mapped to the class.\n\n## The Index class\n\nYou must create your own `Index` class to define the name of internal _index_\nfor Elasticsearch, as well as to define the mapping type and define any entity\nproperties you need like virtual properties. As you have to\n[use only one mapping type for each _index_](https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html),\nyou can use the same name for both (the default behavior when _type_ is\nundefined is use singular version of _index_ name). Index types were removed\nin ElasticSearch 7.\n\n```php\nuse Cake\\ElasticSearch\\Index;\n\nclass CommentsIndex extends Index\n{\n    /**\n     * The name of index in Elasticsearch\n     *\n     * @return  string\n     */\n    public function getName()\n    {\n        return 'comments';\n    }\n}\n```\n\n## Running tests\n\nWe recommend using the included `docker-compose.yml` for doing local\ndevelopment. The `Dockerfile` contains the development environment, and an\nElasticsearch container will be downloaded and started on port 9200.\n\n```bash\n# Start elasticsearch\ndocker-compose up -d\n\n# Open an terminal in the development environment\ndocker-compose run console bash\n```\n\nOnce inside the container you can install dependencies and run tests.\n\n```bash\n./composer.phar install\nvendor/bin/phpunit\n```\n\n**Warning**: Please, be very carefully when running tests as the Fixture will\ncreate and drop Elasticsearch indexes for its internal structure. Don't run tests\nin production or development machines where you have important data into your\nElasticsearch instance.\n\nAssuming you have PHPUnit installed system wide using one of the methods stated\n[here](https://phpunit.de/manual/current/en/installation.html), you can run the\ntests for CakePHP by doing the following:\n\n1. Copy `phpunit.xml.dist` to `phpunit.xml`\n2. Run `phpunit`\n","funding_links":[],"categories":["Search"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakephp%2Felastic-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcakephp%2Felastic-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakephp%2Felastic-search/lists"}