{"id":19188779,"url":"https://github.com/miquido/elasticsearch-dbal","last_synced_at":"2025-05-08T02:47:26.160Z","repository":{"id":57017335,"uuid":"144589552","full_name":"miquido/elasticsearch-dbal","owner":"miquido","description":"The project was made by Miquido. https://www.miquido.com/","archived":false,"fork":false,"pushed_at":"2018-10-05T09:58:24.000Z","size":36,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T06:35:00.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miquido.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-13T14:16:23.000Z","updated_at":"2023-09-25T07:17:14.000Z","dependencies_parsed_at":"2022-08-22T11:31:45.818Z","dependency_job_id":null,"html_url":"https://github.com/miquido/elasticsearch-dbal","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2Felasticsearch-dbal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2Felasticsearch-dbal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2Felasticsearch-dbal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2Felasticsearch-dbal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miquido","download_url":"https://codeload.github.com/miquido/elasticsearch-dbal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252989941,"owners_count":21836665,"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":[],"created_at":"2024-11-09T11:26:00.384Z","updated_at":"2025-05-08T02:47:26.138Z","avatar_url":"https://github.com/miquido.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://travis-ci.org/miquido/elasticsearch-dbal.svg?branch=master)](https://travis-ci.org/miquido/elasticsearch-dbal)\n[![Maintainability](https://api.codeclimate.com/v1/badges/608064935172a46d839a/maintainability)](https://codeclimate.com/github/miquido/elasticsearch-dbal/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/608064935172a46d839a/test_coverage)](https://codeclimate.com/github/miquido/elasticsearch-dbal/test_coverage)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n\n# Elasticsearch DBAL\n\nWrapper for [https://github.com/ruflin/Elastica](https://github.com/ruflin/Elastica)\n\n- [Installation guide](#installation)\n- [Code Samples](#code-samples)\n- [Contributing](#contributing)\n\n## Installation \nUse [Composer](https://getcomposer.org) to install the package:\n\n```shell\ncomposer require miquido/elasticsearch-dbal\n```\n\n## Code Samples\n- [Initialize DBAL object](#initialize-dbal-object)\n- [Count documents](#count-documents)\n- [Search documents](#search-documents)\n- [SearchResult and Document objects](#searchresult-and-document-objects)\n- [Create new documents](#create-new-documents)\n- [Update documents](#update-documents)\n- [Delete documents](#delete-documents)\n\n### Initialize *DBAL* object\n*Miquido\\Elasticsearch\\DBAL* requires *Elastica\\Type* object:\n```php\n\u003c?php\n\nuse Miquido\\Elasticsearch\\DBAL;\n\n$client = new \\Elastica\\Client();\n$type = $client-\u003egetIndex('index_name')-\u003egetType('type_name');\n\n$dbal = new DBAL($type);\n```\n\n### Count documents\n\n```php\n\u003c?php\n\n$dbal-\u003ecountAll(); // count all documents in the type\n$dbal-\u003ecount(new \\Elastica\\Query(new \\Elastica\\Query\\Terms('field_name', [1, 2, 3]))); // count documents matching query\n\n```\n\n### Search documents\n```php\n\u003c?php\n\nuse Miquido\\Elasticsearch\\DBAL;\n\n$dbal = new DBAL($type);\n\n$query = new \\Elastica\\Query(new \\Elastica\\Query\\Terms('field_name', [1, 2, 3]));\n\n$dbal-\u003esearch($query); // returns 10 documents (default ElasticSearch setting)\n$dbal-\u003esearchAll($query); // returns all documents (uses scroll api)\n$dbal-\u003efindOne($query);\n$dbal-\u003efindByIds('id1', 'id2', 'id2');\n\n```\n\n### SearchResult and Document objects\n*search()*, *searchAll()* and *findByIds()* methods return instance of [Miquido\\Elasticsearch\\Result\\SearchResultInterface](src/Result/SearchResultInterface.php)\n\n*findOne()* method returns instance of [Miquido\\Elasticsearch\\Document\\DocumentInterface](src/Document/DocumentInterface.php)\n\nPlease also check [miquido/data-structure](https://github.com/miquido/data-structure) library for more details about classes used inside Documents objects.\n```php\n\u003c?php\n\nuse Miquido\\Elasticsearch\\DBAL;\n\n$dbal = new DBAL($type);\n\n$result = $dbal-\u003esearch(new \\Elastica\\Query(new \\Elastica\\Query\\MatchAll()));\n$result-\u003ecount(); // returns number of documents in result\n$result-\u003egetTotalHits(); // returns number of documents matching the query\n$result-\u003egetTime(); // returns time of the query\n$result-\u003egetDocuments()-\u003egetAll(); // returns instances of Documents \n$result-\u003egetDocuments()-\u003egetData(); // returns instance of Miquido\\DataStructure\\Map\\MapCollectionInterface \n\n$document = $dbal-\u003efindOne(new \\Elastica\\Query());\n$document-\u003egetId(); // string\n$document-\u003egetData(); // returns instance of Miquido\\DataStructure\\Map\\MapInterface  \n```\n\n### Create new documents\n```php\n\u003c?php\n\nuse Miquido\\Elasticsearch\\DBAL;\nuse Miquido\\Elasticsearch\\Document\\Document;\nuse Miquido\\DataStructure\\Map\\Map;\n\n$dbal = new DBAL($type);\n$dbal-\u003eadd(new Document(\n    null /* or string if you want to choose your own ID */, \n    new Map([\n        'name' =\u003e 'John',\n        'surname' =\u003e 'Smith',\n        'age' =\u003e 40,\n    ]))\n);\n\n// you can also add many documents at once\n$dbal-\u003ebulkAdd($document1, $document2, ...);\n\n```\n### Update documents\n```php\n\u003c?php\n\nuse Miquido\\Elasticsearch\\DBAL;\nuse Miquido\\Elasticsearch\\Document\\Document;\nuse Miquido\\DataStructure\\Map\\Map;\n\n$dbal = new DBAL($type);\n\n// this method will only update 'age' field in document with ID 'documentId'\n$dbal-\u003eupdatePatch(new Document('documentId', new Map([\n    'age' =\u003e 41,\n])));\n\n// you can also add many documents at once\n$dbal-\u003ebulkUpdatePatch($document1, $document2, ...);\n```\n\n### Delete documents\n```php\n\u003c?php\n\nuse Miquido\\Elasticsearch\\DBAL;\n\n$dbal = new DBAL($type);\n$dbal-\u003edeleteByIds('id1', 'id2', 'id3');\n```\n\n## Contributing\n\nPull requests, bug fixes and issue reports are welcome.\nBefore proposing a change, please discuss your change by raising an issue.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiquido%2Felasticsearch-dbal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiquido%2Felasticsearch-dbal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiquido%2Felasticsearch-dbal/lists"}