org.elasticsearch.client.IndicesClient Java Examples
The following examples show how to use
org.elasticsearch.client.IndicesClient.
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: ElasticSearchImpl.java From core-ng-project with Apache License 2.0 | 6 votes |
@Override public void putIndex(String index, String source) { var watch = new StopWatch(); try { IndicesClient client = client().indices(); CreateIndexRequest request = new CreateIndexRequest(index).source(new BytesArray(source), XContentType.JSON); boolean exists = client.exists(new GetIndexRequest(index), RequestOptions.DEFAULT); if (!exists) { client.create(request, RequestOptions.DEFAULT); } else { // only try to update mappings, as for settings it generally requires to close index first then open after update logger.info("index already exists, update mapping, index={}", index); client.putMapping(new PutMappingRequest(index).source(request.mappings(), XContentType.JSON), RequestOptions.DEFAULT); } } catch (IOException e) { throw new UncheckedIOException(e); } finally { logger.info("put index, index={}, source={}, elapsed={}", index, source, watch.elapsed()); } }
Example #2
Source File: ElasticsearchAdminHandler.java From arctic-sea with Apache License 2.0 | 5 votes |
@Override public synchronized void createSchema() throws IOException { IndicesClient indices = getClient().indices(); if (indices.exists(new GetIndexRequest(settings.getIndexId()), RequestOptions.DEFAULT)) { logger.info("Index {} already exists", settings.getIndexId()); // update mapping Integer version = getCurrentVersion(); logger.info("Elasticsearch schema version is {}", version); if (version == null) { throw new ConfigurationError("Database inconsistency. Metadata version not found in type %s", MetadataDataMapping.METADATA_TYPE_NAME); } if (version != schemas.getSchemaVersion()) { throw new ConfigurationError( "Database schema version inconsistency. Version numbers don't match. " + "Database version number %d <-> Application version number %d", version, schemas.getSchemaVersion()); } addUuidToMetadataIfNeeded(settings.getUuid()); } else { logger.info("Index {} not exists creating a new one now.", settings.getIndexId()); // create metadata table and index table table Map<String, Object> mapping = new HashMap<>(); mapping.put(MetadataDataMapping.METADATA_TYPE_NAME, schemas.getMetadataSchema()); mapping.put(settings.getTypeId(), schemas.getSchema()); CreateIndexResponse response = indices .create(new CreateIndexRequest(settings.getIndexId()).mapping(mapping), RequestOptions.DEFAULT); logger.debug("Created indices: {}", response); // insert metadata values createMetadataType(schemas.getSchemaVersion()); } }
Example #3
Source File: ElasticsearchAdminHandlerIT.java From arctic-sea with Apache License 2.0 | 5 votes |
@Test public void createNewDatabase() throws InterruptedException, IOException { adminHandler.createSchema(); IndicesClient indices = getEmbeddedClient().indices(); boolean index = indices.exists(new GetIndexRequest(clientSettings.getIndexId()), RequestOptions.DEFAULT); Assertions.assertTrue(index); GetResponse resp = getEmbeddedClient() .get(new GetRequest(clientSettings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID), RequestOptions.DEFAULT); Assertions.assertEquals(1, resp.getSourceAsMap().get(MetadataDataMapping.METADATA_VERSION_FIELD.getName())); }
Example #4
Source File: LegacyElasticSearchClient.java From adaptive-alerting with Apache License 2.0 | 4 votes |
public IndicesClient indices() { return client.indices(); }
Example #5
Source File: ReactorElasticSearchClient.java From james-project with Apache License 2.0 | 4 votes |
public IndicesClient indices() { return client.indices(); }
Example #6
Source File: EnhancedRestHighLevelClient.java From super-cloudops with Apache License 2.0 | 2 votes |
/** * 获取索引操作client ,使用完该客户端后需要主动调用 ${@link #releaseClient()} 方法释放client到资源池 * * @return */ public final IndicesClient indices() { return (IndicesClient) exec((r) -> r.indices(), false); }