脚本语言编辑
API允许一个设置索引脚本的语言与之交互。如果一个人没有提供默认将使用脚本语言。
指标管理编辑
访问指标Java API,您需要调用 indices()
方法从一个 AdminClient
:
IndicesAdminClient indicesAdminClient = client.admin().indices();
在本指南中,我们将使用 client.admin().indices()
.
创建索引编辑
使用一个 IndicesAdminClient
与所有默认设置,您可以创建一个索引,没有映射:
client.admin().indices().prepareCreate("twitter").get();
指标设置编辑
每个索引创建可以有与之关联的特定设置。
client.admin().indices().prepareCreate("twitter")
.setSettings(Settings.builder() //1
.put("index.number_of_shards", 3)
.put("index.number_of_replicas", 2)
)
.get(); //2
把映射编辑
把地图API允许您添加一个新的类型在创建索引:
client.admin().indices().prepareCreate("twitter") //1
.addMapping("tweet", "{\n" + //2
" \"tweet\": {\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }")
.get();
创建一个索引被称为 | |
它还增加了一个 |
PUT API还允许添加新的类型映射到现有的指数:
client.admin().indices().preparePutMapping("twitter") //1
.setType("user") //2
.setSource("{\n" + //3
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }\n" +
"}")
.get();
// You can also provide the type in the source document
client.admin().indices().preparePutMapping("twitter")
.setType("user")
.setSource("{\n" +
" \"user\":{\n" + //4
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}")
.get();
您可以使用相同的API来更新现有的映射:
client.admin().indices().preparePutMapping("twitter") //1
.setType("tweet") //2
.setSource("{\n" + //3
" \"properties\": {\n" +
" \"user_name\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }\n" +
"}")
.get();
刷新编辑
刷新API允许显式地刷新一个或多个指数:
client.admin().indices().prepareRefresh().get(); //1
client.admin().indices()
.prepareRefresh("twitter") //2
.get();
client.admin().indices()
.prepareRefresh("twitter", "company") //3
.get();
得到设置编辑
得到设置API允许检索设置索引/指数:
GetSettingsResponse response = client.admin().indices()
.prepareGetSettings("company", "employee").get();
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) { //1
String index = cursor.key; //2
Settings settings = cursor.value; //3
Integer shards = settings.getAsInt("index.number_of_shards", null); //4
Integer replicas = settings.getAsInt("index.number_of_replicas", null); //5
}//6
更新指标设置编辑
你可以更改索引设置通过调用:
client.admin().indices().prepareUpdateSettings("twitter") //1
.setSettings(Settings.builder() //2
.put("index.number_of_replicas", 0)
)
.get();
索引更新 | |
设置 |