delete elasticsearch index when indexing to clean up properly
[phorkie.git] / src / phorkie / Database / Adapter / Elasticsearch / Setup.php
index 066a21c2253f7019959388e40192267709fa7030..0df287475051740bdf8b9bf84de692dbb1080f4f 100644 (file)
@@ -10,12 +10,29 @@ class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
 
     public function setup()
     {
-        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
-            $this->searchInstance . 'repo/_mapping',
+        $r = new \HTTP_Request2(
+            $this->searchInstance . '/_mapping', \HTTP_Request2::METHOD_GET
+        );
+        $res = $r->send();
+        if ($res->getStatus() == 404) {
+            $this->reset();
+        }
+    }
+
+    public function reset()
+    {
+        $r = new \HTTP_Request2(
+            $this->searchInstance,
             \HTTP_Request2::METHOD_DELETE
         );
         $r->send();
 
+        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
+            $this->searchInstance,
+            \HTTP_Request2::METHOD_PUT
+        );
+        $r->send();
+
         //create mapping
         //mapping for repositories
         $r = new Database_Adapter_Elasticsearch_HTTPRequest(