Skip to content

Instantly share code, notes, and snippets.

@acampagna
Created January 30, 2013 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save acampagna/4f88033204cd761abec0 to your computer and use it in GitHub Desktop.
Save acampagna/4f88033204cd761abec0 to your computer and use it in GitHub Desktop.
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