本文整理汇总了Java中org.elasticsearch.action.admin.indices.create.CreateIndexRequest类的典型用法代码示例。如果您正苦于以下问题:Java CreateIndexRequest类的具体用法?Java CreateIndexRequest怎么用?Java CreateIndexRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateIndexRequest类属于org.elasticsearch.action.admin.indices.create包,在下文中一共展示了CreateIndexRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createChatsIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
private void createChatsIndex(IndicesAdminClient indices) {
CreateIndexRequest createBuilder = new CreateIndexRequest("chats");
try {
// @formatter:off
XContentBuilder mappingBuilder = XContentFactory.jsonBuilder()
.startObject()
.startObject("chat")
.startObject("properties")
.startObject("date")
.field("type", "long")
.endObject()
.startObject("type")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject();
createBuilder.mapping("chat", mappingBuilder);
// @formatter:on
} catch (IOException e) {
e.printStackTrace();
}
indices.create(createBuilder);
}
示例2: prepareRequest
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
if (request.hasContent()) {
createIndexRequest.source(request.content(), request.getXContentType());
}
createIndexRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false));
createIndexRequest.timeout(request.paramAsTime("timeout", createIndexRequest.timeout()));
createIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createIndexRequest.masterNodeTimeout()));
createIndexRequest.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
return channel -> client.admin().indices().create(createIndexRequest, new AcknowledgedRestListener<CreateIndexResponse>(channel) {
@Override
public void addCustomFields(XContentBuilder builder, CreateIndexResponse response) throws IOException {
response.addCustomFields(builder);
}
});
}
示例3: createIndexAndExecuteUpsertRequest
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
private void createIndexAndExecuteUpsertRequest(final UpsertByIdNode.Item item,
final SettableFuture<TaskResult> futureResult) {
transportCreateIndexAction.execute(
new CreateIndexRequest(item.index()).cause("upsert single item"),
new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse createIndexResponse) {
executeUpsertRequest(item, futureResult);
}
@Override
public void onFailure(Throwable e) {
e = ExceptionsHelper.unwrapCause(e);
if (e instanceof IndexAlreadyExistsException) {
executeUpsertRequest(item, futureResult);
} else {
futureResult.setException(e);
}
}
});
}
示例4: doExecute
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@Override
protected void doExecute(final Task task, final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
ClusterState state = clusterService.state();
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
createIndexAction.execute(task, new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)")
.masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(task, request, listener);
}
@Override
public void onFailure(Throwable e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
// we have the index, do it
innerExecute(task, request, listener);
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(task, request, listener);
}
}
示例5: ElasticMap
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
public ElasticMap(Future<AsyncStorage<Value>> future, StorageContext<Value> context) throws IOException {
this.context = context;
this.logger = context.logger(getClass());
try {
this.client = new PreBuiltTransportClient(Settings.builder()
.put("client.transport.sniff", true)
.build())
.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(context.host()), context.port()));
client.admin().indices().create(new CreateIndexRequest(context.database())).get();
} catch (UnknownHostException | InterruptedException | ExecutionException e) {
logger.onError(e);
}
future.complete(this);
}
示例6: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
/**
* Create index.
*
* @return True if index create ok, false if index is already exist.
*/
public boolean createIndex() {
// check index exist:
IndicesAdminClient idc = client.admin().indices();
IndicesExistsResponse ier = idc.exists(new IndicesExistsRequest(index)).actionGet();
if (!ier.isExists()) {
log.info("Index not found. Auto-create...");
// create index:
CreateIndexResponse cir = idc.create(new CreateIndexRequest(index)).actionGet();
if (!cir.isAcknowledged()) {
throw new RuntimeException("Failed to create index.");
}
return true;
}
return false;
}
示例7: initCluster
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@BeforeClass
public void initCluster() throws IOException {
client = getClient();
CreateIndexRequest indexRequest = new CreateIndexRequest(INDEX_NAME);
assertTrue(client.admin().indices().create(indexRequest).actionGet().isAcknowledged());
String mapping = ResourceUtils.asString("mapping_request.json");
PutMappingRequestBuilder builder = new PutMappingRequestBuilder(client, PutMappingAction.INSTANCE);
PutMappingRequest request = builder.setIndices(INDEX_NAME).setType(INDEX_TYPE).setSource(mapping).request();
assertTrue(client.admin().indices().putMapping(request).actionGet().isAcknowledged());
String doc01 = ResourceUtils.asString("documents/doc01.json");
String doc02 = ResourceUtils.asString("documents/doc02.json");
IndexRequestBuilder indexBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE, INDEX_NAME).setType(INDEX_TYPE);
assertTrue(client.index(indexBuilder.setId("1").setSource(doc01).request()).actionGet().isCreated());
assertTrue(client.index(indexBuilder.setId("2").setSource(doc02).request()).actionGet().isCreated());
client.admin().indices().flush(new FlushRequest(INDEX_NAME)).actionGet();
defaultProperties = new DefaultProperties("default.properties");
}
示例8: initCluster
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@BeforeClass
public void initCluster() throws IOException {
client = getClient();
CreateIndexRequest indexRequest = new CreateIndexRequest(INDEX_NAME);
assertTrue(client.admin().indices().create(indexRequest).actionGet().isAcknowledged());
String mapping = ResourceUtils.asString("mapping_request.json");
PutMappingRequestBuilder builder = new PutMappingRequestBuilder(client, PutMappingAction.INSTANCE);
PutMappingRequest request = builder.setIndices(INDEX_NAME).setType(INDEX_TYPE).setSource(mapping).request();
assertTrue(client.admin().indices().putMapping(request).actionGet().isAcknowledged());
String doc01 = ResourceUtils.asString("documents/doc01.json");
String doc02 = ResourceUtils.asString("documents/doc02.json");
IndexRequestBuilder indexBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE, INDEX_NAME).setType(INDEX_TYPE);
assertTrue(client.index(indexBuilder.setId("1").setSource(doc01).request()).actionGet().isCreated());
assertTrue(client.index(indexBuilder.setId("2").setSource(doc02).request()).actionGet().isCreated());
client.admin().indices().flush(new FlushRequest(INDEX_NAME)).actionGet();
defaultProperties = new DefaultProperties("default.properties");
}
示例9: createIndexOnNode
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
protected CreateIndexResponse createIndexOnNode(String indexName) {
if (indexExists(indexName)) {
ES_LOGGER.warn("Index [" + indexName + "] already exists. Attempting to delete it.");
DeleteIndexResponse builder = this.deleteIndexOnNode(indexName);
ES_LOGGER.info("Delete index [{}] acknowledged [{}]", indexName, builder.isAcknowledged());
}
Settings settings = Settings.settingsBuilder()
.put("index.mapper.dynamic", true)
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.build();
CreateIndexResponse createIndexResponse = node.client().admin().indices()
.create((new CreateIndexRequest(indexName)).settings(settings)).actionGet(TIMEOUT);
waitForGreenClusterState(indexName);
return createIndexResponse;
}
示例10: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@Override
public void createIndex(String indexName, String indexType, Object source) {
logger.info(String.format("Generating index %s ...", indexName));
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
if (indexType != null) {
String settings = generateSettings(source);
if (settings != null) {
logger.info("Setting up...");
createIndexRequest.settings(settings);
}
}
logger.info("Mapping...");
String mapping = generateMapping(source);
createIndexRequest.mapping(indexType, mapping);
try {
CreateIndexResponse response = elasticSearchClient.admin().indices().create(createIndexRequest).actionGet();
if (response.isAcknowledged()) {
logger.info(String.format("Index %s created!", indexName));
}
} catch (ElasticsearchException ex) {
logger.error(String.format("Index %s was not created due some errors.", indexName), ex);
}
}
示例11: setUp
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
mapper = spy(mapper);
elasticsearchServer = new MockElasticsearchServer(UUID.randomUUID().toString());
ElasticsearchUtils.initializeMappings(elasticsearchServer.getClient());
elasticsearchConnection = Mockito.mock(ElasticsearchConnection.class);
when(elasticsearchConnection.getClient()).thenReturn(elasticsearchServer.getClient());
//Create index for table meta. Not created automatically
Settings indexSettings = ImmutableSettings.settingsBuilder().put("number_of_replicas", 0).build();
CreateIndexRequest createRequest = new CreateIndexRequest(TableMapStore.TABLE_META_INDEX).settings(indexSettings);
elasticsearchServer.getClient().admin().indices().create(createRequest).actionGet();
elasticsearchServer.getClient().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
TableMapStore.Factory factory = new TableMapStore.Factory(elasticsearchConnection);
tableMapStore = factory.newMapStore(null, null);
}
示例12: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@BeforeMethod
protected void createIndex() {
logger.info("creating index [" + INDEX + "]");
CreateIndexRequest createIndexRequest = createIndexRequest(INDEX);
String settings = getSettings();
if (settings != null)
createIndexRequest.settings(getSettings());
String mapping = getMapping();
if (mapping != null)
createIndexRequest.mapping(TYPE, getMapping());
assertThat("Index creation", node.client().admin().indices().create(createIndexRequest).actionGet().isAcknowledged());
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
}
示例13: setup
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
public void setup() throws IOException, NoSuchFieldException, IllegalAccessException {
String key;
CreateIndexResponse ciResp;
Reflections reflections = new Reflections("org.apache.usergrid.chop.webapp.dao");
Set<Class<? extends Dao>> daoClasses = reflections.getSubTypesOf(Dao.class);
IndicesAdminClient client = elasticSearchClient.getClient().admin().indices();
for (Class<? extends Dao> daoClass : daoClasses) {
key = daoClass.getDeclaredField("DAO_INDEX_KEY").get(null).toString();
if (!client.exists(new IndicesExistsRequest(key)).actionGet().isExists()) {
ciResp = client.create(new CreateIndexRequest(key)).actionGet();
if (ciResp.isAcknowledged()) {
LOG.debug("Index for key {} didn't exist, now created", key);
} else {
LOG.debug("Could not create index for key: {}", key);
}
} else {
LOG.debug("Key {} already exists", key);
}
}
}
示例14: startup
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
public void startup() throws Exception {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
settings.put("node.name", "testnode");
settings.put("gateway.type", "none");
settings.put("path.data", "target/search-data");
settings.put("http.enabled", true);
settings.put("http.port", HTTP_PORT);
// settings.put("index.compound_format", false);
settings.put("transport.tcp.port", TRANSPORT_PORT);
_node = NodeBuilder.nodeBuilder().settings(settings).clusterName(CLUSTER_NAME).data(true).local(false).node();
try (Client client = _node.client()) {
IndicesAdminClient indicesAdmin = client.admin().indices();
if (!indicesAdmin.exists(new IndicesExistsRequest(INDEX_NAME)).actionGet().isExists()) {
indicesAdmin.create(new CreateIndexRequest(INDEX_NAME)).actionGet();
}
}
System.out.println("--- ElasticSearchTestServer started ---");
}
示例15: readFrom
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
shrinkIndexRequest = new CreateIndexRequest();
shrinkIndexRequest.readFrom(in);
sourceIndex = in.readString();
}