Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ElasticquentTrait.php #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/ElasticquentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,36 @@ public static function getMapping()

return $instance->getElasticSearchClient()->indices()->getMapping($params);
}

/**
* Create Mapping.
* Use if you want to create mappings after the index has already being created.
*@return array
*/
public static function createMapping()
{
$instance = new static;

$mappings = $instance->getMappingProperties();

if(!is_null($mappings)) {

$index = array(
'index' => $instance->getIndexName(),
);

$settings = $instance->getIndexSettings();
if (!is_null($settings)) {
$index['body']['settings'] = $settings;
}
$index['body']['properties'] = $mappings;
$index['type'] = $instance->getTypeName();

return $instance->getElasticSearchClient()->indices()->putMapping($index);
}

return false;
}

/**
* Put Mapping.
Expand Down