{"id":15029271,"url":"https://github.com/bakaphp/phalcon-elasticsearch","last_synced_at":"2025-04-09T20:40:31.748Z","repository":{"id":62491311,"uuid":"132397729","full_name":"bakaphp/phalcon-elasticsearch","owner":"bakaphp","description":"Elastic Search library for PhalconPHP Api's","archived":false,"fork":false,"pushed_at":"2020-04-29T22:35:36.000Z","size":101,"stargazers_count":5,"open_issues_count":4,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-23T22:36:59.201Z","etag":null,"topics":["baka","elasticsearch","phalcon","phalcon-php","php","php71"],"latest_commit_sha":null,"homepage":null,"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/bakaphp.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":"2018-05-07T02:41:23.000Z","updated_at":"2023-09-21T20:02:20.000Z","dependencies_parsed_at":"2022-11-02T11:16:27.328Z","dependency_job_id":null,"html_url":"https://github.com/bakaphp/phalcon-elasticsearch","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakaphp%2Fphalcon-elasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakaphp%2Fphalcon-elasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakaphp%2Fphalcon-elasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakaphp%2Fphalcon-elasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bakaphp","download_url":"https://codeload.github.com/bakaphp/phalcon-elasticsearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248109613,"owners_count":21049343,"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":["baka","elasticsearch","phalcon","phalcon-php","php","php71"],"created_at":"2024-09-24T20:10:10.282Z","updated_at":"2025-04-09T20:40:31.725Z","avatar_url":"https://github.com/bakaphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Baka Phalcon Elastic Search\n\nPhalcon Elastic Search package to index / query model with relationship easily\n\n## Table of Contents\n1. [Indexing](#indexing)\n    1. [Create](#indexing-create)\n    1. [Insert](#indexing-insert)\n2. [Search](#markdown-header-QueryParser)\n4. [Testing](#markdown-header-QueryParser-Extended)\n\n## Installing\nPackages:\n- `\"elasticsearch/elasticsearch\": \"~2.0@beta\"`\n- `\"baka/database\": \"dev-master\"`\n- `\"phalcon/incubator\": \"~3.0\",\"`\n\nAdd elastic configuration to config.php\n\n```php\n\n#config.php\n\n'namespace' =\u003e [\n    'controller' =\u003e 'Project\\Controllers',\n    'models' =\u003e 'Project\\Models',\n],\n\n'elasticSearch' =\u003e [\n    'hosts' =\u003e [getenv('ELASTIC_HOST')], //change to pass array\n],\n\n```\n\nadd queue to DI\n\n```php\n\n#service.php\n\n$di-\u003eset('queue', function () use ($config) {\n    //Connect to the queue\n    $queue = new Phalcon\\Queue\\Beanstalk\\Extended([\n        'host' =\u003e $config-\u003ebeanstalk-\u003ehost,\n        'prefix' =\u003e $config-\u003ebeanstalk-\u003eprefix,\n    ]);\n\n    return $queue;\n});\n\n```\n\n## Indexing\nTo create a Index in Elastic search first you will need to configure a CLI project and extend it from `IndexTasksBuilder` , after doing that just run the following command\n\n` php cli/app.php IndexBuilder createIndex ModelName 3`\n\nWhere `4` is the normal of levels you want the relationships to index for example\n```\nLevel 1\n Class A \n - Relation BelongsTo Class B\n\n Level 2\n Class A \n - Relation BelongsTo Class B\n - - Class B\n - - - Relation HasMany Class C\n\nLevel 3\n Class A \n - Relation BelongsTo Class B\n - - Class B\n - - - Relation HasMany Class C\n - - - - Class C\n - - - - - Relation HasMany Class D\n``` \n*We can ignore a relationship if we specify on the options `'elasticSearch' =\u003e false`*\n\nI wont recommend going beyond 4 levels if it not neede, it will use a lot of space.\n\nIf you get a error related to `nestedLimit` , you can use a 4th param to specify the amount the index limit\n\n` php cli/app.php IndexBuilder createIndex ModelName 3 100`\n\n### Indexing Queue\n\nNow that you created a Index we need to index the data, for that your model will need to extend from `\\Baka\\Elasticsearch\\Model` . After every update | save we will send the information to a queue where the process will insert or update the info in elastic\n\n```php\n\n\u003c?php\n\n\nclass Users extends \\Baka\\Elasticsearch\\Model\n{\n\n}\n```\n\nQueue\n\n`php cli/app.php IndexBuilder queue ModelName`\n\nExample:\n`php cli/app.php IndexBuilder queue Users`\n\n\n## Search\n\nIn order to simply searching en elastic search with elastic you most install this extension https://github.com/NLPchina/elasticsearch-sql\n\nNow your search controller must use our trait\n\n```php\n\n\u003c?php\n\n/**\n * Search controller\n */\nclass SearchController extends BaseController\n{\n    use \\Baka\\Elasticsearch\\SearchTrait\n}\n```\n\nAnd Follow the same query structure has Baka Http\n\n`https://api.dev/v1/search/indexName?sort=id|asc\u0026q=(is_deleted:0,relationship.type_id:1)\u0026fields=id,first_name,last_name,relationship.name,relationship.relationshipb.name`\n\nExample\n\n`https://api.dev/v1/search/users?sort=first_name|asc\u0026q=(is_deleted:0,users_statuses_id:,first_name:,last_name:)\u0026fields=id,first_name,last_name,potentiality,classification,userssprograms.id,events_satisfaction,is_prospect,gifts.name,is_key_users,dob,companies.name,companies.companiesstatuses.name,companies.rnc,position`\n\n## Testing\n\n```\ncodecept run\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakaphp%2Fphalcon-elasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbakaphp%2Fphalcon-elasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakaphp%2Fphalcon-elasticsearch/lists"}