https://github.com/svilborg/elasticsearch-model
Elasticsearch Client Wrapper for creating Models
https://github.com/svilborg/elasticsearch-model
crud elasticsearch index library model php type wrapper
Last synced: about 1 month ago
JSON representation
Elasticsearch Client Wrapper for creating Models
- Host: GitHub
- URL: https://github.com/svilborg/elasticsearch-model
- Owner: svilborg
- Created: 2018-06-06T17:56:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-07T10:20:31.000Z (about 8 years ago)
- Last Synced: 2025-05-30T19:16:51.034Z (about 1 year ago)
- Topics: crud, elasticsearch, index, library, model, php, type, wrapper
- Language: PHP
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# elasticsearch-model
Elasticsearch Models creation Library
#### Usage
Simple model definition
```php
class Item extends ModelBase implements Gettable, Indexable, Updatable, Deletable, Searchable
{
use Get, Index, Update, Delete, Search, Management;
/**
*
* @var string
*/
protected $index = "inventory";
/**
*
* @var string
*/
protected $type = "items";
}
```
Creating a Document
```php
$item = new Item();
$response = $item->indexDocument(15, [
"name" => "blue",
"count" => 24
]);
```
Exended Model Definition
```php
class Item extends ModelBase implements Gettable, Indexable, Updatable, Deletable, Searchable
{
use Get, Index, Update, Delete, Search, Management;
/**
*
* @var string
*/
protected $index = "inventory";
/**
*
* @var string
*/
protected $type = "items";
protected $settings = [
'number_of_shards' => 1,
'number_of_replicas' => 0
];
protected $mapping = [
'_default_' => [
'properties' => [
'name' => [
'type' => 'keyword',
'copy_to' => 'combined'
],
'count' => [
'type' => 'keyword',
'copy_to' => 'combined'
],
'combined' => [
'type' => 'keyword',
]
]
]
];
}
```
Initlaizing an Index with mapping
```php
$item = new Item();
$response = $item->initIndex();
```