{"id":23853676,"url":"https://github.com/aviationcode/elasticsearch","last_synced_at":"2025-10-12T05:07:18.296Z","repository":{"id":36498131,"uuid":"227918837","full_name":"AviationCode/elasticsearch","owner":"AviationCode","description":"Laravel elasticsearch eloquent integration","archived":false,"fork":false,"pushed_at":"2024-05-17T12:04:24.000Z","size":435,"stargazers_count":5,"open_issues_count":6,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-08T00:40:55.803Z","etag":null,"topics":["elasticsearch","hacktoberfest","laravel","package"],"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/AviationCode.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-12-13T20:42:07.000Z","updated_at":"2024-05-17T12:02:47.000Z","dependencies_parsed_at":"2024-05-17T12:47:58.715Z","dependency_job_id":"088a247f-3c48-4d93-994f-eae801fefbec","html_url":"https://github.com/AviationCode/elasticsearch","commit_stats":{"total_commits":212,"total_committers":8,"mean_commits":26.5,"dds":"0.32547169811320753","last_synced_commit":"c3b4eca1e5fea84d2a4484378f5e30c3602ed822"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/AviationCode/elasticsearch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviationCode%2Felasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviationCode%2Felasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviationCode%2Felasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviationCode%2Felasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AviationCode","download_url":"https://codeload.github.com/AviationCode/elasticsearch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviationCode%2Felasticsearch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010342,"owners_count":26084738,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","hacktoberfest","laravel","package"],"created_at":"2025-01-02T23:18:59.552Z","updated_at":"2025-10-12T05:07:18.267Z","avatar_url":"https://github.com/AviationCode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elasticsearch\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Build Status][ico-travis]][link-travis]\n\nThis package wraps the `elasticsearch/elasticsearch` composer package with laravel integration.\nAdding support to easily use your eloquent models with elastic search.  \n\n## Installation\n\nVia Composer\n\n``` bash\n$ composer require aviationcode/elasticsearch\n```\n## Configuration\n\nBy default, we use `localhost:9200` to search your elasticsearch instance. If this is the case no configuration is required at all.\nYou can use the following `.env` settings to configure how we connect to your elasticsearch instance.\n\n| Name             | Type      | Default     | Description\n|------------------|:---------:|-------------|------------\n| ELASTIC_HOST     | `string`  | `localhost` | The IP or host to connect to \n| ELASTIC_PORT     | `integer` | 9200        | The port used to connect\n| ELASTIC_SCHEME   | `string`  | `http`      | Use of HTTP or HTTPS \n| ELASTIC_USER     | `string`  | `null`      | The Basic auth username\n| ELASTIC_PASSWORD | `string`  | `null`      | The Basic auth password\n\n## Usage\n\nConfigure a model to use elasticsearch by using the `ElasticSearchable` trait or extend using `ElasticsearchModel`. \n\n```php\nuse AviationCode\\Elasticsearch\\Model\\ElasticSearchable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Article extends Model\n{\n    use ElasticSearchable;\n}\n```\n\n### Custom mapping properties\n\nWe attempt to detect the [elasticsearch mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) fields from your `$dates` array and primary key. We are unable to correctly detect other fields. \n\nElasticsearch will in this case attempt to guess the mapping field automatically however it is recommended to explicitly define these fields as the correct type.\n\n```php\nuse AviationCode\\Elasticsearch\\Model\\ElasticSearchable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Article extends Model\n{\n    use ElasticSearchable;\n    \n    public $mapping = [\n        'category' =\u003e ['type' =\u003e 'keyword'],\n        'properties' =\u003e ['type' =\u003e 'object', 'dynamic' =\u003e true],\n        'ip' =\u003e ['type' =\u003e 'ip'],\n    ];\n}\n```\n\nUse the elasticsearch documentation to find all options available.\n\n### Non numeric keys\n\nWhen using UUID's or other non numeric keys make sure you configure your model correctly.\nThis will make sure we use the correct mapping inside your model mapping. \n\n```php\nuse AviationCode\\Elasticsearch\\Model\\ElasticSearchable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Article extends Model\n{\n    use ElasticSearchable;\n\n    protected $keyType = 'string';    \n}\n```\n\n### Custom index name\n\nYou may want to use a custom name or use existing index name with your eloquent model. Just like you can define the database table used you can also define the index named used.\n\n```php\nuse AviationCode\\Elasticsearch\\Model\\ElasticSearchable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Article extends Model\n{\n    use ElasticSearchable;\n    \n    public $indexName = 'my_custom_index_name';\n}\n```\n\n**Note**: You can still use `$indexVersion` to add `vX` at the end of your index.\n\n### Versioned index\n\nIf you like to version your index names you can use the `$indexVersion` name. This will add `_vX` at the end of your index name where X is the index version.\n```php\nuse AviationCode\\Elasticsearch\\Model\\ElasticSearchable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Article extends Model\n{\n    use ElasticSearchable;\n    \n    public $indexVersion = 2;\n}\n```\n\n### Query\n\n```php\nnamespace App\\Http\\Controllers;\n\nuse App\\Article;\nuse AviationCode\\Elasticsearch\\Facades\\Elasticsearch;\nuse AviationCode\\Elasticsearch\\Query\\Dsl\\Boolean\\Filter;\nuse AviationCode\\Elasticsearch\\Query\\Dsl\\Boolean\\Must;\nuse Illuminate\\Http\\Request;\n\nclass ArticleController \n{\n    public function index(Request $request)\n    {\n        return Elasticsearch::forModel(Article::class)\n            -\u003equery()\n            -\u003efilter(function (Filter $filter) use ($request) {\n                if ($user = $request-\u003equery('user')) {\n                    $filter-\u003eterm('user', $user); \n                }\n            })\n            -\u003emust(function (Must $must) use ($request) {\n                if ($query = $request-\u003equery('q')) {\n                    $must-\u003equeryString($query); \n                }        \n            })\n            -\u003eget();\n    }\n}\n```\n\nWithout an eloquent model.\n```php\nnamespace App\\Http\\Controllers;\n\nuse App\\Article;\nuse AviationCode\\Elasticsearch\\Facades\\Elasticsearch;\nuse AviationCode\\Elasticsearch\\Query\\Dsl\\Boolean\\Filter;\nuse AviationCode\\Elasticsearch\\Query\\Dsl\\Boolean\\Must;\nuse Illuminate\\Http\\Request;\n\nclass ArticleController \n{\n    public function index(Request $request)\n    {\n        return Elasticsearch::query('article')\n            -\u003efilter(function (Filter $filter) use ($request) {\n                if ($user = $request-\u003equery('user')) {\n                    $filter-\u003eterm('user', $user); \n                }\n            })\n            -\u003emust(function (Must $must) use ($request) {\n                if ($query = $request-\u003equery('q')) {\n                    $must-\u003equeryString($query); \n                }        \n            })\n            -\u003eget();\n    }\n}\n```\n\n### Aggregations\n\nUsing aggregations with model.\n```php\nnamespace App\\Http\\Controllers;\n\nuse App\\Article;\nuse AviationCode\\Elasticsearch\\Facades\\Elasticsearch;\n\nclass ArticlesPerUserPerDayController \n{\n    public function index()\n    {\n        $qb = Elasticsearch::forModel(Article::class)-\u003equery();\n\n        $qb-\u003eaggregations()\n            -\u003edateHistogram('date', 'created_at', '1d')\n            -\u003eterms('date.users', 'user');\n\n        return $qb-\u003eget()-\u003eaggregations;\n    }\n}\n```\n\nUsing aggregations without an eloquent model.\n```php\nnamespace App\\Http\\Controllers;\n\nuse App\\Article;\nuse AviationCode\\Elasticsearch\\Facades\\Elasticsearch;\n\nclass ArticlesPerUserPerDayController \n{\n    public function index()\n    {\n        $qb = Elasticsearch::query('article');\n\n        $qb-\u003eaggregations()\n            -\u003edateHistogram('date', 'created_at', '1d')\n            -\u003eterms('date.users', 'user');\n\n        return $qb-\u003eget()-\u003eaggregations;\n    }\n}\n```\n\n## Console Commands \n\n### `elastic:create-index` Creating elasticsearch index\n\n## Change log\n\nPlease see the [changelog](changelog.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [contributing.md](contributing.md) for details and a todolist.\n\n## Security\n\nIf you discover a security vulnerability within elasticsearch package, please send an e-mail to Ken Andries at ken.andries.1992@gmail.com. All security vulnerabilities will be promptly addressed.\n\n## Credits\n\n- [Ken Andries][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nlicense. Please see the [license file](license.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/aviationcode/elasticsearch.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/aviationcode/elasticsearch.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/aviationcode/elasticsearch/master.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/aviationcode/elasticsearch\n[link-downloads]: https://packagist.org/packages/aviationcode/elasticsearch\n[link-travis]: https://travis-ci.org/aviationcode/elasticsearch\n[link-styleci]: https://styleci.io/repos/227918837\n[link-author]: https://github.com/douglasdc3\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviationcode%2Felasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faviationcode%2Felasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviationcode%2Felasticsearch/lists"}