ElasticSearch(十三) Indices Administration
IndicesAdminClient indicesAdminClient = client.admin().indices();
Create Index
client.admin().indices().prepareCreate("twitter").get();
Index Settings
client.admin().indices().prepareCreate("twitter") .setSettings(Settings.builder()
.put("index.number_of_shards", 3) .put("index.number_of_replicas", 2) ) .get();
static final Builder builder = Settings.builder().put("index.analysis.search_analyzer.default.type", "ik_smart")
.put("index.analysis.analyzer.default.type", "ik_max_word").put("index.mapping.total_fields.limit", 30000);
index.mapping.total_fields.limit 默认值:1000
Refresh
client.admin().indices().prepareRefresh().get();
client.admin().indices() .prepareRefresh("twitter")
.get(); client.admin().indices() .prepareRefresh("twitter", "company")
.get();
Get Settings
GetSettingsResponse response = client.admin().indices() .prepareGetSettings("company", "employee").get();
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) {
String index = cursor.key;
Settings settings = cursor.value;
Integer shards = settings.getAsInt("index.number_of_shards", null);
Integer replicas = settings.getAsInt("index.number_of_replicas", null);
}
Update Indices Settings
client.admin().indices().prepareUpdateSettings("twitter")
.setSettings(Settings.builder()
.put("index.number_of_replicas", 0) ).get();