{"id":14981111,"url":"https://github.com/novaway/elasticsearch-client","last_synced_at":"2025-06-10T10:06:25.843Z","repository":{"id":57028685,"uuid":"94904027","full_name":"novaway/elasticsearch-client","owner":"novaway","description":"A lightweight PHP 7.0+ client for Elasticsearch, providing features over Elasticsearch-PHP","archived":false,"fork":false,"pushed_at":"2022-04-08T15:21:56.000Z","size":265,"stargazers_count":5,"open_issues_count":4,"forks_count":7,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-24T06:47:37.566Z","etag":null,"topics":["elasticsearch","elasticsearch-php","library","php"],"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/novaway.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-06-20T15:04:37.000Z","updated_at":"2020-04-16T16:22:41.000Z","dependencies_parsed_at":"2022-08-23T16:30:15.472Z","dependency_job_id":null,"html_url":"https://github.com/novaway/elasticsearch-client","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novaway%2Felasticsearch-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novaway%2Felasticsearch-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novaway%2Felasticsearch-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novaway%2Felasticsearch-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novaway","download_url":"https://codeload.github.com/novaway/elasticsearch-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novaway%2Felasticsearch-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259053405,"owners_count":22798435,"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":["elasticsearch","elasticsearch-php","library","php"],"created_at":"2024-09-24T14:02:55.891Z","updated_at":"2025-06-10T10:06:25.800Z","avatar_url":"https://github.com/novaway.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Novaway ElasticSearch Client\n\nNote : this project is discontinued in favor of the [ElasticsearchBundle](https://github.com/novaway/elasticsearch-bundle), as it was more or less trying to do what elastica does already well\n\nA lightweight PHP 7.0+ client for Elasticsearch, providing features over [Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)\n\n## Compatibility\n\nThis branch is tested and compatible with ElasticSearch 6.*\n\nThe compatibility with ElasticSearch 5.* is supported, and should work, but is to be considered hazardous.\n\n## Installation\n\nInstall using [composer](https://getcomposer.org):\n\n```shell\n$ composer require novaway/elasticsearch-client\n```\n\n## Usage\n\n### Create an index\n\nThe first thing you'll need to do to use this library is to instatiate an index. This will be the keystone of the client.\n\n```php\n$index = new \\Novaway\\ElasticsearchClient\\Index(\n\t['127.0.0.1:9200'],  \t# elasticsearch hosts\n\t'main_index',\t\t\t\t# index name\n\t[\n        'settings' =\u003e [\n            'number_of_shards' =\u003e 3,\n            'number_of_replicas' =\u003e 2\n        ],\n        'mappings' =\u003e [\n            'my_type' =\u003e [\n                '_source' =\u003e [\n                    'enabled' =\u003e true\n                ],\n                'properties' =\u003e [\n                    'first_name' =\u003e [\n                        'type' =\u003e 'string',\n                        'analyzer' =\u003e 'standard'\n                    ],\n                    'age' =\u003e [\n                        'type' =\u003e 'integer'\n                    ]\n                ]\n            ]\n        ]\n    ]    \n);\n```\n\n### Index an object\n\nIn order to be searched, objects should be indexed as a serialized version. In order to be indexed, Object should implement `\\Novaway\\ElasticsearchClient\\Indexable` interface.\n\nBy default, objects are serialized with [Elasticsearch-PHP's SmartSerializer](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_serializers.html#_smartserializer), but you can choose to [use a custom serializer](doc/working-with-a-custom-serializer.md).\n\n```php\n$objectIndexer = new \\Novaway\\ElasticsearchClient\\ObjectIndexer($index);\n$objectIndexer-\u003eindex($object, 'my_type');\n```\n\n#### Remove an object from index\n\nTo remove an object from the index, the process is still \n\n```php\n$objectIndexer = new \\Novaway\\ElasticsearchClient\\ObjectIndexer($index);\n$objectIndexer-\u003eremove($object, 'my_type');\n\n// Alternatively, you can remove an indexed object knowing only it's ID.\n$objectIndexer-\u003eremoveById($objectId, 'my_type');\n```\n\n### Search the index\n\n#### Basic match query\n\nFirst, create a `QueryExecutor`.\n\n```php\n$queryExecutor = new \\Novaway\\ElasticsearchClient\\QueryExecutor($index);\n```\n\nUse the `QueryBuilder` to build your query and execute it.\n\n```php\nuse Novaway\\ElasticsearchClient\\Query\\CombiningFactor;\n\n$queryBody = QueryBuilder::createNew()\n\t\t\t\t\t-\u003ematch('first_name', 'John', CombiningFactor::MUST)\n\t\t\t\t\t-\u003egetQueryBody()\n;\n$queryExecutor-\u003eexecute($queryBody, 'my_type');\n```\n\nThe `QueryBuilder` allow you to define a limit and an offset for a search result, and choose the minimum score to display.\n\n```php\nconst MIN_SCORE = 0.4;\nconst OFFSET = 0;\nconst LIMIT = 10;\n\n$queryBuilder = QueryBuilder::createNew(0, 10, 0.3);\n```\n\n#### Advanced Querying\n\nThis client provide several ways to improve querying :\n\n- Filtering *(missing documentation)*\n- [Aggregations](doc/aggregation.md)\n- Result Formating *(missing documentation)*\n\n\n### Clear the index\n\nYou might want, for some reason, to purge an index. The `reload` method drops and recreates the index.\n\n```php\n$index-\u003ereload();\n```\n\n### Hotswapping\n\nYou will want to reindex all your data sometimes.\n\nIt is possible to do it without downtime using the hotswap mechanisme\n\n```php\n$index-\u003ehotswapToTmp();\n// at that point, all your search request will go to the tmp index, and your create/delete will go to the main index\n// when your are done reindexing your data, simply call \n$index-\u003ehotswapToMain()\n\n```\n\n\n## Recommended usage with Symfony\n\nIf you are using this library in a symfony project, we recommend to use it as service.\n\n```yml\n# services.yml\nparameters:\n    myapp.search.myindex.config:\n        settings:\n            number_of_shards : 1\n            number_of_replicas : 1\n        mappings:\n            my_type:\n                _source : { enabled : true }\n                properties:\n                    first_name:\n                        type: string\n                        analyzer: standard\n                    age:\n                        type: integer\n                        \nservices:\n    myapp.search.index:\n        class: Novaway\\ElasticsearchClient\\Index\n        arguments:\n            - ['127.0.0.1:9200'] #define it in the parameter.yml file\n            - 'myapp_myindex_%kernel.environment%'\n            - 'myapp.search.myindex.config'\n\n    myapp.search.object_indexer:\n        class: Novaway\\ElasticsearchClient\\ObjectIndexer\n        arguments:\n            - '@myapp.search.index'\n\n    myapp.search.query_executor:\n        class: Novaway\\ElasticsearchClient\\QueryExecutor\n        arguments:\n            - '@myapp.search.index'\n```\n\nThen you'll only have to work with the `myapp.search.object_indexer` and `myapp.search.query_executor` services.\n\n## Testing\n\nA testing environment is provided using a dockerized version of elasticsearch.\n\nTesting is done using the [Atoum](http://atoum.org/) framework for unit testing and the [Behat](http://behat.org/en/latest/) framework for behavior testing.\n\nA `Makefile` provide useful commands for testing, so you can run the full test suite by running :\n```sh\n$ make test\n```\n\n## License\n\nThis library is published under [MIT license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovaway%2Felasticsearch-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovaway%2Felasticsearch-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovaway%2Felasticsearch-client/lists"}