{"id":19638029,"url":"https://github.com/simon28082/elasticsearch","last_synced_at":"2025-06-22T18:08:58.442Z","repository":{"id":55501803,"uuid":"100927763","full_name":"simon28082/elasticsearch","owner":"simon28082","description":"Use SQL statements to query elasticsearch","archived":false,"fork":false,"pushed_at":"2020-12-26T10:59:04.000Z","size":105,"stargazers_count":103,"open_issues_count":0,"forks_count":15,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-12T16:57:57.944Z","etag":null,"topics":["elasticsearch","laravel","orm","php","query","sql"],"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/simon28082.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://blog.crcms.cn/reward"]}},"created_at":"2017-08-21T07:57:30.000Z","updated_at":"2024-01-08T10:52:54.000Z","dependencies_parsed_at":"2022-08-15T01:50:55.235Z","dependency_job_id":null,"html_url":"https://github.com/simon28082/elasticsearch","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/simon28082/elasticsearch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon28082%2Felasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon28082%2Felasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon28082%2Felasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon28082%2Felasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simon28082","download_url":"https://codeload.github.com/simon28082/elasticsearch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon28082%2Felasticsearch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261338998,"owners_count":23143900,"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","laravel","orm","php","query","sql"],"created_at":"2024-11-11T12:37:26.508Z","updated_at":"2025-06-22T18:08:53.429Z","avatar_url":"https://github.com/simon28082.png","language":"PHP","readme":"# Crcms Elasticsearch\n\n\n[![Latest Stable Version](https://poser.pugx.org/crcms/elasticsearch/v/stable)](https://packagist.org/packages/crcms/elasticsearch)\n[![License](https://poser.pugx.org/crcms/elasticsearch/license)](https://packagist.org/packages/crcms/elasticsearch)\n[![StyleCI](https://github.styleci.io/repos/100927763/shield?branch=master)](https://github.styleci.io/repos/100927763)\n\n## Version Matrix\n\n| Elasticsearch Version | crcms/elasticsearch Branch |\n| --------------------- | ------------------------ |\n| \u003e= 7.0                | master(beta unstable)                      |\n| \u003e= 6.0                | 1.*                      |\n| \u003e= 5.0, \u003c 6.0         | 0.*                      |\n\n## Install\n\nYou can install the package via composer:\n\n```\ncomposer require crcms/elasticsearch\n```\n\n\u003e Please install if you want to use the latest version `dev-master`\n\n## Use\n\n### Non-Laravel framework\n\n```php\n// select config path\n$config = require 'search.php';\n$builder = Factory::builder($config);\n```\n\n### Laravel\n\nModify `config / app.php` If the version is less \u003c= 5.5\n```\n'providers' =\u003e [\n    CrCms\\ElasticSearch\\LaravelServiceProvider::class,\n]\n\n```\n\nIf you'd like to make configuration changes in the configuration file you can pubish it with the following Aritsan command:\n```\nphp artisan vendor:publish --provider=\"CrCms\\ElasticSearch\\LaravelServiceProvider\"\n```\n\n\n\n## Quickstart\n\n### Create\n\n```php\n$builder-\u003eindex('index')-\u003etype('type')-\u003ecreate([\n    'key' =\u003e 'value'\n]);\n\n// return a collection\n$builder-\u003eindex('index')-\u003etype('type')-\u003ecreateCollection([\n    'key' =\u003e 'value'\n]);\n```\n\n### Update\n\n```php\n$builder-\u003eindex('index')-\u003etype('type')-\u003eupdate([\n    'key' =\u003e 'value1'\n]);\n\n```\n\n### Delete\n\n```php\n$builder-\u003eindex('index')-\u003etype('type')-\u003edelete($result-\u003e_id);\n```\n\n### Select\n\n```php\n\n$builder = $builder-\u003eindex('index')-\u003etype('type');\n\t\n//SQL:select ... where id = 1 limit 1;\n$result = $builder-\u003ewhereTerm('id',1)-\u003efirst();\n\n//SQL:select ... where (key=1 or key=2) and key1=1\n$result = $builder-\u003ewhere(function (Query $inQuery) {\n    $inQuery-\u003ewhereTerm('key',1)-\u003eorWhereTerm('key',2)\n})-\u003ewhereTerm('key1',1)-\u003eget();\n\n```\n\n### More\n\nskip / take\n```php\n$builder-\u003etake(10)-\u003eget(); // or limit(10)\n$builder-\u003eoffset(10)-\u003etake(10)-\u003eget(); // or skip(10)\n```\n\nterm query\n```php\n$builder-\u003ewhereTerm('key',value)-\u003efirst();\n```\n\nmatch query\n```php\n$builder-\u003ewhereMatch('key',value)-\u003efirst();\n```\n\nrange query\n```php\n$builder-\u003ewhereBetween('key',[value1,value2])-\u003efirst();\n```\n\nwhere in query\n```php\n$builder-\u003ewhereIn('key',[value1,value2])-\u003efirst();\n```\n\nlogic query\n```php\n$builder-\u003ewhereTerm('key',value)-\u003eorWhereTerm('key2',value)-\u003efirst();\n```\n\nnested query\n```php\n$result = $builder-\u003ewhere(function (Builder $inQuery) {\n    $inQuery-\u003ewhereTerm('key',1)-\u003eorWhereTerm('key',2)\n})-\u003ewhereTerm('key1',1)-\u003eget();\n```\n\n### Available conditions\n\n```php\npublic function select($columns): self\n```\n\n```php\npublic function where($column, $operator = null, $value = null, $leaf = 'term', $boolean = 'and'): self\n```\n\n\n```php\npublic function orWhere($field, $operator = null, $value = null, $leaf = 'term'): self\n```\n\n```php\npublic function whereMatch($field, $value, $boolean = 'and'): self\n```\n\n```php\npublic function orWhereMatch($field, $value, $boolean = 'and'): self\n```\n\n```php\npublic function whereTerm($field, $value, $boolean = 'and'): self\n```\n\n```php\npublic function whereIn($field, array $value)\n```\n\n```php\npublic function orWhereIn($field, array $value)\n```\n\n```php\npublic function orWhereTerm($field, $value, $boolean = 'or'): self\n```\n\n```php\npublic function whereRange($field, $operator = null, $value = null, $boolean = 'and'): self\n```\n\n```php\npublic function orWhereRange($field, $operator = null, $value = null): self\n```\n\n```php\npublic function whereBetween($field, array $values, $boolean = 'and'): self\n```\n```php\npublic function whereNotBetween($field, array $values): self\n```\n```php\npublic function orWhereNotBetween(string $field, array $values): self\n```\n```php\npublic function whereExists($field, $boolean = 'and'): self\n```\n```php\npublic function whereNotExists($field, $boolean = 'and'): self\n```\n\n```php\npublic function orWhereBetween($field, array $values): self\n```\n\n```php\npublic function orderBy(string $field, $sort): self\n```\n\n```php\npublic function scroll(string $scroll): self\n```\n\n```php\npublic function aggBy($field, $type): self\n```\n\n```php\npublic function select($columns): self\n```\n\n### Result Method\n```php\npublic function get(): Collection\n```\n\n```php\npublic function paginate(int $page, int $perPage = 15): Collection\n```\n\n```php\npublic function first()\n```\n\n```php\npublic function byId($id)\n```\n\n```php\npublic function byIdOrFail($id): stdClass\n```\n\n```php\npublic function chunk(callable $callback, $limit = 2000, $scroll = '10m')\n```\n\n```php\npublic function create(array $data, $id = null, $key = 'id'): stdClass\n```\n\n```php\npublic function update($id, array $data): bool\n```\n\n```php\npublic function delete($id)\n```\n\n```php\npublic function count(): int\n```\n\n### Log\n\n```php\n//open log\n$builder-\u003eenableQueryLog();\n\n//all query log\ndump($build-\u003egetQueryLog());\n\n//last query log\ndump($build-\u003egetLastQueryLog());\n```\n\n### Elastisearch object\n\n```php\ngetElasticSearch() // or search()\n```\n\n\u003e If you want to expand more, you can use this method, call https://github.com/elastic/elasticsearch-php\n\n## Other\nFor more examples, please see test cases\nhttps://github.com/crcms/elasticsearch/blob/master/tests/BuildTest.php\n## License\n[MIT license](https://opensource.org/licenses/MIT)\n","funding_links":["https://blog.crcms.cn/reward"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon28082%2Felasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimon28082%2Felasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon28082%2Felasticsearch/lists"}