Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bakaphp/phalcon-elasticsearch
Elastic Search library for PhalconPHP Api's
https://github.com/bakaphp/phalcon-elasticsearch
baka elasticsearch phalcon phalcon-php php php71
Last synced: 2 months ago
JSON representation
Elastic Search library for PhalconPHP Api's
- Host: GitHub
- URL: https://github.com/bakaphp/phalcon-elasticsearch
- Owner: bakaphp
- License: mit
- Created: 2018-05-07T02:41:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-29T22:35:36.000Z (over 4 years ago)
- Last Synced: 2024-09-29T20:22:47.622Z (3 months ago)
- Topics: baka, elasticsearch, phalcon, phalcon-php, php, php71
- Language: PHP
- Size: 98.6 KB
- Stars: 5
- Watchers: 6
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Baka Phalcon Elastic Search
Phalcon Elastic Search package to index / query model with relationship easily
## Table of Contents
1. [Indexing](#indexing)
1. [Create](#indexing-create)
1. [Insert](#indexing-insert)
2. [Search](#markdown-header-QueryParser)
4. [Testing](#markdown-header-QueryParser-Extended)## Installing
Packages:
- `"elasticsearch/elasticsearch": "~2.0@beta"`
- `"baka/database": "dev-master"`
- `"phalcon/incubator": "~3.0","`Add elastic configuration to config.php
```php
#config.php
'namespace' => [
'controller' => 'Project\Controllers',
'models' => 'Project\Models',
],'elasticSearch' => [
'hosts' => [getenv('ELASTIC_HOST')], //change to pass array
],```
add queue to DI
```php
#service.php
$di->set('queue', function () use ($config) {
//Connect to the queue
$queue = new Phalcon\Queue\Beanstalk\Extended([
'host' => $config->beanstalk->host,
'prefix' => $config->beanstalk->prefix,
]);return $queue;
});```
## Indexing
To 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` php cli/app.php IndexBuilder createIndex ModelName 3`
Where `4` is the normal of levels you want the relationships to index for example
```
Level 1
Class A
- Relation BelongsTo Class BLevel 2
Class A
- Relation BelongsTo Class B
- - Class B
- - - Relation HasMany Class CLevel 3
Class A
- Relation BelongsTo Class B
- - Class B
- - - Relation HasMany Class C
- - - - Class C
- - - - - Relation HasMany Class D
```
*We can ignore a relationship if we specify on the options `'elasticSearch' => false`*I wont recommend going beyond 4 levels if it not neede, it will use a lot of space.
If you get a error related to `nestedLimit` , you can use a 4th param to specify the amount the index limit
` php cli/app.php IndexBuilder createIndex ModelName 3 100`
### Indexing Queue
Now 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
```php