Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.