org.elasticsearch.client.indices.GetIndexRequest Java Examples
The following examples show how to use
org.elasticsearch.client.indices.GetIndexRequest.
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: ElasticSearchClient.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
public boolean indexExists() { try { GetIndexRequest indexRequest = new GetIndexRequest(index); return client.indices().exists(indexRequest, RequestOptions.DEFAULT); } catch (IOException e) { /* It may return if failed to parse the response, on timeout or no response from the ES instance. Assuming it is more likely to timeout or provide no reply either the during the start up or on overloaded CI environments, we log the I/O error and try again */ LOG.error("I/O error trying to query for index existence: {}", e.getMessage(), e); } return false; }
Example #2
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 #3
Source File: DataServiceImpl.java From java-11-examples with Apache License 2.0 | 5 votes |
@Override public Optional<Boolean> isIndexCreated(String indexName) { try { GetIndexRequest request = new GetIndexRequest(indexName); boolean exists = client.indices().exists(request, RequestOptions.DEFAULT); return Optional.of(Boolean.valueOf(exists)); } catch (IOException e) { return Optional.empty(); } }
Example #4
Source File: FactSearchManager.java From act-platform with ISC License | 5 votes |
private boolean indexExists() { try { GetIndexRequest request = new GetIndexRequest(INDEX_NAME); return clientFactory.getClient().indices().exists(request, RequestOptions.DEFAULT); } catch (ElasticsearchException | IOException ex) { throw logAndExit(ex, "Could not perform request to verify if index exists."); } }
Example #5
Source File: ElasticVindClient.java From vind with Apache License 2.0 | 5 votes |
public boolean indexExists() throws IOException { try { final RequestOptions authenticatedDefaultRequest = RequestOptions.DEFAULT; final GetIndexRequest existsRequest = new GetIndexRequest(getDefaultIndex()); return this.client.indices().exists(existsRequest, authenticatedDefaultRequest); } catch (Exception e) { throw new IOException(String.format("Index does not exist: %s", getDefaultIndex()),e); } }
Example #6
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 #7
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 #8
Source File: ElasticsearchAdminHandlerIT.java From arctic-sea with Apache License 2.0 | 5 votes |
@Test public void enableKibanaPreConfLoadingFromDefaultFile() throws InterruptedException, IOException { settings.setKibanaConfigEnable(true); settings.setKibanaConfPath(null); adminHandler.init(); Thread.sleep(2500); Assertions.assertTrue(getEmbeddedClient().indices().exists(new GetIndexRequest(".kibana"), RequestOptions.DEFAULT)); }
Example #9
Source File: EsUtil.java From bookmark with MIT License | 5 votes |
/** * Description: 判断某个index是否存在 * * @param index index名 * @return boolean * @author fanxb * @date 2019/7/24 14:57 */ public boolean indexExist(String index) throws Exception { if (!status) { return false; } GetIndexRequest request = new GetIndexRequest(index); request.local(false); request.humanReadable(true); request.includeDefaults(false); return client.indices().exists(request, RequestOptions.DEFAULT); }
Example #10
Source File: ElasticExporter.java From LoggerPlusPlus with GNU Affero General Public License v3.0 | 5 votes |
private void createIndices() throws IOException { GetIndexRequest request = new GetIndexRequest(this.indexName); boolean exists = httpClient.indices().exists(request, RequestOptions.DEFAULT); if(!exists) { CreateIndexRequest _request = new CreateIndexRequest(this.indexName); httpClient.indices().create(_request, RequestOptions.DEFAULT); } }
Example #11
Source File: ElasticSearchUtils.java From bdt with Apache License 2.0 | 5 votes |
/** * Check if an index exists in ES * * @param indexName * @return true if the index exists or false if the index does not exits. */ public boolean indexExists(String indexName) { try { GetIndexRequest request = new GetIndexRequest(indexName); return client.indices().exists(request, RequestOptions.DEFAULT); } catch (IOException e) { throw new ElasticsearchException("Error checking if index " + indexName + " exists"); } }
Example #12
Source File: KibanaImporterIT.java From arctic-sea with Apache License 2.0 | 4 votes |
@Test public void importInvalidJson() throws InterruptedException, JsonParseException, JsonMappingException, IOException { new KibanaImporter(getEmbeddedClient(), "local-index", "").importJson("semmi latnivali nincs itt"); Thread.sleep(1500); Assertions.assertFalse(getEmbeddedClient().indices().exists(new GetIndexRequest(".kibana"), RequestOptions.DEFAULT)); }
Example #13
Source File: ElasticSearch7Client.java From skywalking with Apache License 2.0 | 4 votes |
public boolean isExistsIndex(String indexName) throws IOException { indexName = formatIndexName(indexName); GetIndexRequest request = new GetIndexRequest(indexName); return client.indices().exists(request, RequestOptions.DEFAULT); }
Example #14
Source File: ElasticsearchIndexManager.java From syncope with Apache License 2.0 | 4 votes |
public boolean existsIndex(final String domain, final AnyTypeKind kind) throws IOException { return client.indices().exists( new GetIndexRequest(ElasticsearchUtils.getContextDomainName(domain, kind)), RequestOptions.DEFAULT); }
Example #15
Source File: EsUtil.java From demo-project with MIT License | 3 votes |
/** * Description: 判断某个index是否存在 * * @param index index名 * @return boolean * @author fanxb * @date 2019/7/24 14:57 */ public boolean indexExist(String index) throws Exception { GetIndexRequest request = new GetIndexRequest(index); request.local(false); request.humanReadable(true); request.includeDefaults(false); return client.indices().exists(request, RequestOptions.DEFAULT); }