-
-
Save acampagna/4f88033204cd761abec0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import org.elasticsearch.client.Client | |
import org.elasticsearch.common.settings.ImmutableSettings | |
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest | |
import org.elasticsearch.indices.IndexMissingException | |
object IndexingUtils { | |
def createMapping(client: Client, indexName: String, indexType: String, mappingFile: String) { | |
//Submit mappings to index | |
client.admin().indices() | |
.preparePutMapping(indexName) | |
.setType(indexType) | |
.setSource(Utils.loadFileAsString(mappingFile)) | |
.execute().actionGet() | |
} | |
def createIndex(client: Client, indexName: String, indexFile: String) { | |
//Create index | |
client.admin().indices().prepareCreate(indexName) | |
.setSettings(ImmutableSettings.settingsBuilder() | |
//.put("index.refresh_interval", "-1") | |
.loadFromSource(Utils.loadFileAsString(indexFile))) | |
.execute() | |
.actionGet() | |
} | |
def deleteIndex(client: Client, indexName: String) { | |
//Delete index if it already exists | |
try { | |
client.admin().indices() | |
.delete(new DeleteIndexRequest(indexName)).actionGet() | |
} catch { | |
case e: IndexMissingException => | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment