From 52916fc5f70eecef4f30f516045d0edc44bce65e Mon Sep 17 00:00:00 2001 From: Chad Hoersten Date: Wed, 17 May 2017 10:03:40 -0500 Subject: [PATCH] Added indexExists to check if the index already exists --- src/ElasticquentTrait.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ElasticquentTrait.php b/src/ElasticquentTrait.php index a23e7c4..1d449cb 100644 --- a/src/ElasticquentTrait.php +++ b/src/ElasticquentTrait.php @@ -503,6 +503,26 @@ public static function rebuildMapping() return $instance->putMapping(); } + /** + * Index Exists. + * + * Does this index exist? + * + * @return bool + */ + public static function indexExists() + { + $instance = new static; + + $client = $instance->getElasticSearchClient(); + + $index = array( + 'index' => $instance->getIndexName(), + ); + + return $client->indices()->exists($index); + } + /** * Create Index *