Skip to content

Latest commit

 

History

History
89 lines (71 loc) · 2.62 KB

index-management.md

File metadata and controls

89 lines (71 loc) · 2.62 KB

Index Management

The package includes an indices manager. You are required to register indices that you'll using, whether its for CRUD on the indices or for querying. The index manager is accessed via:

$manager = $searcher->indicesManager();

Defining an index

A simple index exists out of a name and one or more types (+mappings). This can be created as:

class SuggestionsIndex extends \ElasticSearcher\Abstracts\AbstractIndex
{
  public function getName()
  {
    return 'suggestions';
  }

  public function setup()
  {
    $this->setTypes([
      'books' => [
        'properties' => [
          'id' => ['type' => 'integer'],
          'name' => ['type' => 'string'],
        ]
      ],
      'movies' => [
        'properties' => [
          'name' => ['type' => 'string'],
        ]
      ]
    ]);
  }
}

This the minimum required for defining an index. Inside the setup() method you can setup your index further, for example adding settings, aggregations, .... An index is body aware for easy manipulation.

Using re-useable fragments

You can abstract parts of your index to separate classes and re-use them. More about it in the re-useable fragments documentation.

Index registration

The indices should be registered with the indices manager for further use in the package. The index object is only used during this registration, later on it can accessed by its name (via getName).

$suggestionsIndex  = new SuggestionsIndex();

// Single registration
$searcher->indicesManager()->register($suggestionsIndex);

// Grouped registration
$indices = [
  $suggestionsIndex
];
$searcher->indicesManager()->registerIndices($indices);

// Other
$searcher->indexManager()->unregister('suggestions');
$searcher->indexManager()->isRegistered('suggestions');
$searcher->indexManager()->registeredIndices();

Index CRUD

// Indices that exist in the server, not linked to the registered indices.
$searcher->indicesManager()->indices());
$searcher->indicesManager()->get('suggestions'));
$searcher->indicesManager()->getType('suggestions', 'books'));

// Other
$searcher->indicesManager()->exists('listings');
$searcher->indicesManager()->existsType('suggestions', 'movies');
$searcher->indicesManager()->create('suggestions');
$searcher->indicesManager()->update('suggestions');
$searcher->indicesManager()->delete('suggestions');
$searcher->indicesManager()->deleteType('suggestions', 'movies');