Skip to content

Instantly share code, notes, and snippets.

@FredPeal
Last active January 29, 2021 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FredPeal/64def6e2e096aff35c744c9ce8c9eb64 to your computer and use it in GitHub Desktop.
Save FredPeal/64def6e2e096aff35c744c9ce8c9eb64 to your computer and use it in GitHub Desktop.
elastic document model for canvas/core
<?php
namespace Gewaer\ElasticDocuments;
use Baka\Elasticsearch\Objects\Documents;
class Books extends Documents
{
/**
* initialize.
*
* @return void
*/
public function initialize() : void
{
$this->setIndices('books');
$this->addRelation('authors', ['alias' => 'authors', 'elasticAlias' => 'author', 'elasticIndex' => 1]);
}
/**
* structure
*
* @return array
*/
public function structure() : array
{
return [
'id' => $this->integer,
'name' => $this->text,
'authors' => [
'id' => $this->integer,
'name' => $this->text,
'address' => [
'street' => $this->text,
'state' => $this->text,
'city' => $this->text
]
]
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment