secret
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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 =>
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.