org.elasticsearch.action.admin.indices.create.CreateIndexAction Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.create.CreateIndexAction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultElasticSearchAdminService.java From vertx-elasticsearch-service with Apache License 2.0 | 6 votes |
@Override public void createIndex(String index, JsonObject source, CreateIndexOptions options, Handler<AsyncResult<Void>> resultHandler) { final CreateIndexRequestBuilder builder = CreateIndexAction.INSTANCE.newRequestBuilder(service.getClient()) .setIndex(index) .setSource(source.encode(), XContentType.JSON); builder.execute(new ActionListener<CreateIndexResponse>() { @Override public void onResponse(CreateIndexResponse createIndexResponse) { resultHandler.handle(Future.succeededFuture()); } @Override public void onFailure(Exception e) { resultHandler.handle(Future.failedFuture(e)); } }); }
Example #2
Source File: InternalEsClient.java From io with Apache License 2.0 | 6 votes |
/** * インデックスを作成する. * @param index インデックス名 * @param mappings マッピング情報 * @return 非同期応答 */ public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) { this.fireEvent(Event.creatingIndex, index); CreateIndexRequestBuilder cirb = new CreateIndexRequestBuilder(esTransportClient.admin().indices(), CreateIndexAction.INSTANCE, index); // cjkアナライザ設定 Settings.Builder indexSettings = Settings.settingsBuilder(); indexSettings.put("analysis.analyzer.default.type", "cjk"); cirb.setSettings(indexSettings); if (mappings != null) { for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) { cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString()); } } return cirb.execute(); }
Example #3
Source File: AbstractESTest.java From elasticsearch-migration with Apache License 2.0 | 6 votes |
@SneakyThrows protected void createIndex(final String index, final String definition) { final CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client, CreateIndexAction.INSTANCE) .setIndex(index) .setSource(definition, XContentType.JSON); assertThat(createIndexRequestBuilder.get().isAcknowledged(), is(true)); client.admin().indices().prepareFlush(index).setWaitIfOngoing(true).setForce(true).execute().get(); }
Example #4
Source File: BaseMetricTransportClient.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override public BaseMetricTransportClient newIndex(String index, Settings settings, Map<String, String> mappings) { if (client == null) { logger.warn("no client for create index"); return this; } if (index == null) { logger.warn("no index name given to create index"); return this; } CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex(index); if (settings != null) { logger.info("settings = {}", settings.getAsStructuredMap()); createIndexRequestBuilder.setSettings(settings); } if (mappings != null) { for (String type : mappings.keySet()) { logger.info("found mapping for {}", type); createIndexRequestBuilder.addMapping(type, mappings.get(type)); } } createIndexRequestBuilder.execute().actionGet(); logger.info("index {} created", index); return this; }
Example #5
Source File: HttpInvoker.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
public HttpInvoker(Settings settings, ThreadPool threadPool, Headers headers, URL url) { super(settings, threadPool, headers); this.contexts = new HashMap<>(); this.bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setPipelineFactory(new HttpInvoker.HttpClientPipelineFactory()); bootstrap.setOption("tcpNoDelay", true); registerAction(BulkAction.INSTANCE, HttpBulkAction.class); registerAction(CreateIndexAction.INSTANCE, HttpCreateIndexAction.class); registerAction(RefreshAction.INSTANCE, HttpRefreshIndexAction.class); registerAction(ClusterUpdateSettingsAction.INSTANCE, HttpClusterUpdateSettingsAction.class); registerAction(UpdateSettingsAction.INSTANCE, HttpUpdateSettingsAction.class); registerAction(SearchAction.INSTANCE, HttpSearchAction.class); this.url = url; }
Example #6
Source File: LangDetectBinaryTests.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 5 votes |
public void testLangDetectBinary() throws Exception { try { CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex("test"); createIndexRequestBuilder.addMapping("someType", jsonBuilder() .startObject() .startObject("properties") .startObject("content") .field("type", "binary") .startObject("fields") .startObject("language") .field("type", "langdetect") .field("binary", true) .endObject() .endObject() .endObject() .endObject() .endObject()); createIndexRequestBuilder.execute().actionGet(); IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client(), IndexAction.INSTANCE) .setIndex("test").setType("someType").setId("1") //\"God Save the Queen\" (alternatively \"God Save the King\" .setSource("content", "IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg=="); indexRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute().actionGet(); SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE) .setIndices("test") .setQuery(QueryBuilders.termQuery("content.language", "en")) .addStoredField("content.language"); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); assertEquals(1L, searchResponse.getHits().getTotalHits()); assertEquals("en", searchResponse.getHits().getAt(0).field("content.language").getValue()); } finally { DeleteIndexRequestBuilder deleteIndexRequestBuilder = new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, "test"); deleteIndexRequestBuilder.execute().actionGet(); } }
Example #7
Source File: BulkNodeClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public BulkNodeClient newIndex(String index, Settings settings, Map<String, String> mappings) { if (closed) { throw new ElasticsearchException("client is closed"); } if (client == null) { logger.warn("no client for create index"); return this; } if (index == null) { logger.warn("no index name given to create index"); return this; } CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex(index); if (settings != null) { logger.info("settings = {}", settings.getAsStructuredMap()); createIndexRequestBuilder.setSettings(settings); } if (mappings != null) { for (String type : mappings.keySet()) { logger.info("found mapping for {}", type); createIndexRequestBuilder.addMapping(type, mappings.get(type)); } } createIndexRequestBuilder.execute().actionGet(); logger.info("index {} created", index); return this; }
Example #8
Source File: HttpBulkNodeClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public HttpBulkNodeClient newIndex(String index, Settings settings, Map<String, String> mappings) { if (closed) { throw new ElasticsearchException("client is closed"); } if (client == null) { logger.warn("no client for create index"); return this; } if (index == null) { logger.warn("no index name given to create index"); return this; } CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex(index); if (settings != null) { logger.info("settings = {}", settings.getAsStructuredMap()); createIndexRequestBuilder.setSettings(settings); } if (mappings != null) { for (String type : mappings.keySet()) { logger.info("found mapping for {}", type); createIndexRequestBuilder.addMapping(type, mappings.get(type)); } } createIndexRequestBuilder.execute().actionGet(); logger.info("index {} created", index); return this; }
Example #9
Source File: LangDetectGermanTests.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 4 votes |
public void testGermanLanguageCode() throws Exception { try { XContentBuilder builder = jsonBuilder() .startObject() .startObject("properties") .startObject("content") .field("type", "text") .startObject("fields") .startObject("language") .field("type", "langdetect") .array("languages", "zh-cn", "en", "de") .endObject() .endObject() .endObject() .endObject() .endObject(); CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE); createIndexRequestBuilder.setIndex("test").addMapping("someType", builder).execute().actionGet(); String source = "Einigkeit und Recht und Freiheit\n" + "für das deutsche Vaterland!\n" + "Danach lasst uns alle streben\n" + "brüderlich mit Herz und Hand!"; IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client(), IndexAction.INSTANCE) .setIndex("test").setType("someType").setId("1") .setSource("content", source); indexRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute().actionGet(); SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE) .setIndices("test") .setQuery(QueryBuilders.termQuery("content.language", "de")) .addStoredField("content.language"); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); assertEquals(1L, searchResponse.getHits().getTotalHits()); assertEquals("de", searchResponse.getHits().getAt(0).field("content.language").getValue()); } finally { DeleteIndexRequestBuilder deleteIndexRequestBuilder = new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, "test"); deleteIndexRequestBuilder.execute().actionGet(); } }
Example #10
Source File: ActionModule.java From crate with Apache License 2.0 | 4 votes |
static Map<String, ActionHandler<?, ?>> setupActions(List<ActionPlugin> actionPlugins) { // Subclass NamedRegistry for easy registration class ActionRegistry extends NamedRegistry<ActionHandler<?, ?>> { ActionRegistry() { super("action"); } public void register(ActionHandler<?, ?> handler) { register(handler.getAction().name(), handler); } public <Request extends TransportRequest, Response extends TransportResponse> void register( GenericAction<Request, Response> action, Class<? extends TransportAction<Request, Response>> transportAction, Class<?>... supportTransportActions) { register(new ActionHandler<>(action, transportAction, supportTransportActions)); } } ActionRegistry actions = new ActionRegistry(); actions.register(ClusterStateAction.INSTANCE, TransportClusterStateAction.class); actions.register(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class); actions.register(ClusterUpdateSettingsAction.INSTANCE, TransportClusterUpdateSettingsAction.class); actions.register(ClusterRerouteAction.INSTANCE, TransportClusterRerouteAction.class); actions.register(PendingClusterTasksAction.INSTANCE, TransportPendingClusterTasksAction.class); actions.register(PutRepositoryAction.INSTANCE, TransportPutRepositoryAction.class); actions.register(DeleteRepositoryAction.INSTANCE, TransportDeleteRepositoryAction.class); actions.register(GetSnapshotsAction.INSTANCE, TransportGetSnapshotsAction.class); actions.register(DeleteSnapshotAction.INSTANCE, TransportDeleteSnapshotAction.class); actions.register(CreateSnapshotAction.INSTANCE, TransportCreateSnapshotAction.class); actions.register(RestoreSnapshotAction.INSTANCE, TransportRestoreSnapshotAction.class); actions.register(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class); actions.register(CreateIndexAction.INSTANCE, TransportCreateIndexAction.class); actions.register(ResizeAction.INSTANCE, TransportResizeAction.class); actions.register(DeleteIndexAction.INSTANCE, TransportDeleteIndexAction.class); actions.register(PutMappingAction.INSTANCE, TransportPutMappingAction.class); actions.register(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class); actions.register(PutIndexTemplateAction.INSTANCE, TransportPutIndexTemplateAction.class); actions.register(GetIndexTemplatesAction.INSTANCE, TransportGetIndexTemplatesAction.class); actions.register(DeleteIndexTemplateAction.INSTANCE, TransportDeleteIndexTemplateAction.class); actions.register(RefreshAction.INSTANCE, TransportRefreshAction.class); actions.register(SyncedFlushAction.INSTANCE, TransportSyncedFlushAction.class); actions.register(ForceMergeAction.INSTANCE, TransportForceMergeAction.class); actions.register(UpgradeAction.INSTANCE, TransportUpgradeAction.class); actions.register(UpgradeSettingsAction.INSTANCE, TransportUpgradeSettingsAction.class); actions.register(RecoveryAction.INSTANCE, TransportRecoveryAction.class); actions.register(AddVotingConfigExclusionsAction.INSTANCE, TransportAddVotingConfigExclusionsAction.class); actions.register(ClearVotingConfigExclusionsAction.INSTANCE, TransportClearVotingConfigExclusionsAction.class); actions.register(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class); actionPlugins.stream().flatMap(p -> p.getActions().stream()).forEach(actions::register); return unmodifiableMap(actions.getRegistry()); }
Example #11
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public CreateIndexRequestBuilder prepareCreate(String index) { return new CreateIndexRequestBuilder(this, CreateIndexAction.INSTANCE, index); }
Example #12
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public void create(final CreateIndexRequest request, final ActionListener<CreateIndexResponse> listener) { execute(CreateIndexAction.INSTANCE, request, listener); }
Example #13
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public ActionFuture<CreateIndexResponse> create(final CreateIndexRequest request) { return execute(CreateIndexAction.INSTANCE, request); }
Example #14
Source File: LangDetectChineseTests.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 4 votes |
public void testChineseLanguageCode() throws Exception { try { XContentBuilder builder = jsonBuilder() .startObject() .startObject("properties") .startObject("content") .field("type", "text") .startObject("fields") .startObject("language") .field("type", "langdetect") .array("languages", "zh-cn", "en", "de") .endObject() .endObject() .endObject() .endObject() .endObject(); CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE); createIndexRequestBuilder.setIndex("test").addMapping("someType", builder).execute().actionGet(); String source = "位于美国首都华盛顿都会圈的希望中文学校5日晚举办活动庆祝建立20周年。" + "从中国大陆留学生为子女学中文而自发建立的学习班,到学生规模在全美名列前茅的中文学校," + "这个平台的发展也折射出美国的中文教育热度逐步提升。\n" + "希望中文学校是大华盛顿地区最大中文学校,现有7个校区逾4000名学生," + "规模在美国东部数一数二。" + "不过,见证了希望中文学校20年发展的人们起初根本无法想象这个小小的中文教育平台能发展到今日之规模。"; IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client(), IndexAction.INSTANCE) .setIndex("test").setType("someType").setId("1") .setSource("content", source); indexRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute().actionGet(); SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE) .setIndices("test") .setQuery(QueryBuilders.termQuery("content.language", "zh-cn")) .addStoredField("content.language"); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); assertEquals(1L, searchResponse.getHits().getTotalHits()); assertEquals("zh-cn", searchResponse.getHits().getAt(0).field("content.language").getValue()); } finally { DeleteIndexRequestBuilder deleteIndexRequestBuilder = new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, "test"); deleteIndexRequestBuilder.execute().actionGet(); } }
Example #15
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public CreateIndexRequestBuilder prepareCreate(String index) { return new CreateIndexRequestBuilder(this, CreateIndexAction.INSTANCE, index); }
Example #16
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void create(final CreateIndexRequest request, final ActionListener<CreateIndexResponse> listener) { execute(CreateIndexAction.INSTANCE, request, listener); }
Example #17
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public ActionFuture<CreateIndexResponse> create(final CreateIndexRequest request) { return execute(CreateIndexAction.INSTANCE, request); }