private List<String> loadExistingIndicesExceptMetadata(Collection<Index> definitions) { Set<String> definedNames = definitions.stream().map(IndexDefinition.Index::getName).collect(Collectors.toSet()); return Arrays.stream(client.nativeClient().admin().indices().prepareGetIndex().get().getIndices()) .filter(definedNames::contains) .filter(index -> !MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex().equals(index)) .collect(Collectors.toList()); } }
type = indexAndType[1]; indexRequestBuilder = client.admin().indices().prepareGetIndex();
private void updateLogIndexName() { this.logIndexName = this.logIndexPrefix + "_" + SIMPLE_DATE_FORMAT.format(new Date()); try { elasticSearchClient.admin() .indices() .prepareGetIndex() .addIndices(logIndexName) .execute() .actionGet(); } catch (IndexNotFoundException infe) { try { elasticSearchClient.admin() .indices() .prepareCreate(logIndexName) .execute() .actionGet(); } catch (ResourceAlreadyExistsException ilee) { // no-op } catch (Exception e) { logger.error("Failed to update log index name: {}", logIndexName, e); } } }
private void addIndex(String indexName) { try { elasticSearchClient.admin() .indices() .prepareGetIndex() .addIndices(indexName) .execute() .actionGet(); } catch (IndexNotFoundException infe) { try { elasticSearchClient.admin() .indices() .prepareCreate(indexName) .execute() .actionGet(); } catch (ResourceAlreadyExistsException done) { // no-op } } }
private Set<String> getIndices(String indexPattern) { return new HashSet<String>(asList(client.admin().indices().prepareGetIndex().addIndices(indexPattern).get().indices())); } }
@Override protected void after() { if (isCustom) { // delete non-core indices String[] existingIndices = SHARED_NODE.client().admin().indices().prepareGetIndex().get().getIndices(); Stream.of(existingIndices) .filter(i -> !CORE_INDICES_NAMES.contains(i)) .forEach(EsTester::deleteIndexIfExists); } BulkIndexer.delete(client(), new IndexType("_all", ""), client().prepareSearch("_all").setQuery(matchAllQuery())); }
@Override public List<String> getIndices() { String[] indices = this.getClient().admin().indices().prepareGetIndex().get().getIndices(); return Arrays.asList(indices).stream().filter(index -> !index.startsWith(".")).collect(Collectors.toList()); }
@Override public Set<String> getTableNames(String schema) { requireNonNull(schema, "schema is null"); String[] indexs = client.admin().indices().prepareGetIndex().get().indices(); return ImmutableSet.copyOf(indexs); }
@Override public Set<String> getTableNames(String schema) { requireNonNull(schema, "schema is null"); String[] indexs = client.admin().indices().prepareGetIndex().get().indices(); return ImmutableSet.copyOf(indexs); }
@Override public Set<String> getTableNames(String schema) { requireNonNull(schema, "schema is null"); String[] indexs = client.admin().indices().prepareGetIndex().get().indices(); return ImmutableSet.copyOf(indexs); }
@Override public List<String> getIndices() { String[] indices = this.getClient().admin().indices().prepareGetIndex().get().getIndices(); return Arrays.asList(indices).stream().filter(index -> !index.startsWith(".")).collect(Collectors.toList()); }
private List<String> loadExistingIndicesExceptMetadata(Collection<Index> definitions) { Set<String> definedNames = definitions.stream().map(Index::getName).collect(Collectors.toSet()); return Arrays.stream(client.nativeClient().admin().indices().prepareGetIndex().get().getIndices()) .filter(definedNames::contains) .filter(index -> !MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex().equals(index)) .collect(Collectors.toList()); } }
@Override public List<String> call() throws Exception { List<String> allIndices = new ArrayList<String>(); allIndices.add("_all"); allIndices.addAll( asList(client.admin().indices() .prepareGetIndex() .get() .getIndices() ) ); Collections.sort(allIndices); return allIndices; } }
private void ensureIndex(boolean createIfAbsent) throws IOException { GetIndexResponse indexResponse = getElasticClient() .admin() .indices() .prepareGetIndex() .get(elasticsearchProperties.getElasticsearchSearchTimeout()); if (Arrays.asList(indexResponse.getIndices()).stream().anyMatch(i -> i.equalsIgnoreCase(policyIndexName))) { ensureIndexAvailable(); return; } if (!createIfAbsent) { String error = MessageFormat.format("Failed to ensure that the index \"{0}\" exists in Elasticsearch", policyIndexName); logger.error(error); throw new RuntimeException(error); } logger.warn("Index \"{}\" does not exist in Elasticsearch. Creating index...", policyIndexName); try { createIndex(); } catch (IndexAlreadyExistsException e) { logger.warn("Index \"{}\" was found to exist during creation attempt.", policyIndexName); } ensureIndex(false); }
type = indexAndType[1]; indexRequestBuilder = client.admin().indices().prepareGetIndex();
private ImmutableMap<String, IndexState> newIndicesStateCacheInstance(TransportClient client) { try { ImmutableMap.Builder<String, IndexState> cacheBuilder = ImmutableMap.<String, IndexState>builder(); GetIndexResponse getIndexResponse = client.admin().indices().prepareGetIndex().execute().actionGet(); ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth(getIndexResponse.indices()).execute().actionGet(); for (String index : clusterHealthResponse.getIndices().keySet()) { ClusterHealthStatus indexStatus = clusterHealthResponse.getIndices().get(index).getStatus(); cacheBuilder.put(index, IndexState.newIndexState(index, IndexState.IndexStatus.fromString(indexStatus.name()))); } indicesStateCacheMissing = false; return cacheBuilder.build(); } catch (Exception ex) { EsPersistLogger.warn(this, "Failed to get index state.", ex); indicesStateCacheMissing = true; return ImmutableMap.<String, IndexState>builder().build(); } } }
public static Index resolveIndex(String index) { GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().setIndices(index).get(); assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index)); String uuid = getIndexResponse.getSettings().get(index).get(IndexMetaData.SETTING_INDEX_UUID); return new Index(index, uuid); }
public Index resolveIndex(String index) { GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().setIndices(index).get(); assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index)); String uuid = getIndexResponse.getSettings().get(index).get(IndexMetaData.SETTING_INDEX_UUID); return new Index(index, uuid); }
public void dropIndices() throws Exception { String[] indices = runner.admin().indices().prepareGetIndex().execute().get().indices(); for (String index : indices) { if (index.startsWith(ES_INDEX_NAME) || index.startsWith(ES_EXTENDED_DATA_INDEX_NAME_PREFIX)) { LOGGER.info("deleting test index: %s", index); runner.admin().indices().prepareDelete(index).execute().actionGet(); } } }
public void clearIndices(Elasticsearch5SearchIndex searchIndex) throws Exception { String[] indices = runner.admin().indices().prepareGetIndex().execute().get().indices(); for (String index : indices) { if (index.startsWith(ES_INDEX_NAME) || index.startsWith(ES_EXTENDED_DATA_INDEX_NAME_PREFIX)) { LOGGER.info("clearing test index: %s", index); BulkByScrollResponse response = DeleteByQueryAction.INSTANCE.newRequestBuilder(searchIndex.getClient()) .source(index) .get(); LOGGER.info("removed %d documents", response.getDeleted()); } } }