org.elasticsearch.action.admin.indices.get.GetIndexResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.get.GetIndexResponse. 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: PluginClient.java    From openshift-elasticsearch-plugin with Apache License 2.0 6 votes vote down vote up
public CreateIndexResponse copyIndex(final String index, final String target, Settings settings, String... types)
        throws InterruptedException, ExecutionException, IOException {
    return execute(new Callable<CreateIndexResponse>() {

        @Override
        public CreateIndexResponse call() throws Exception {
            LOGGER.trace("Copying {} index to {} for types {}", index, target, types);
            GetIndexResponse response = getIndices(index);
            CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(target);
            if(settings != null) {
                builder.setSettings(settings);
            }
            for (String type : types) {
                builder.addMapping(type, response.mappings().get(index).get(type).getSourceAsMap());
            }
            return builder.get();
        }
        
    });
}
 
Example #2
Source File: PluginClient.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
public GetIndexResponse getIndex(String... indicies) {
    return execute(new Callable<GetIndexResponse>() {
        @Override
        public GetIndexResponse call() throws Exception {
            return client.admin().indices().prepareGetIndex().addIndices(indicies).get();
        }
    });
}
 
Example #3
Source File: Indexer.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
private List<String> findPreviousIndices(IndexConfig indexConfig, ActorStateUpdate update) {
    if (oldVersionOfIndices.containsKey(indexConfig.indexName())) {
        return oldVersionOfIndices.get(indexConfig.indexName());
    }

    List<String> previousIndices = newArrayList();

    try {
        String baseIndexName = indexConfig.indexName();
        String fullIndexName = constructIndexName(indexConfig, update);

        GetIndexResponse indexResponse = client.admin().indices()
                .prepareGetIndex()
                .addIndices(baseIndexName + "*")
                .execute().get();

        for (String index : indexResponse.indices()) {
            if (!index.equals(baseIndexName) && index.equals(fullIndexName)) {
                previousIndices.add(index);
            }
        }
    } catch (Exception e) {
        logger.error("Encountered error while trying to find previous version of indices for base index name {" +
                indexConfig.indexName() +
                "} Old versions of actors indexed here won't be removed", e);
    }

    oldVersionOfIndices.put(indexConfig.indexName(), previousIndices);

    return previousIndices;
}
 
Example #4
Source File: FilterActionTest.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testMissingIndicesQuery() throws FoxtrotException {
    final ObjectMapper mapper = getMapper();
    List<Document> documents = TestUtils.getQueryDocumentsDifferentDate(mapper, new Date(2014 - 1900, 4, 1).getTime());
    documents.addAll(TestUtils.getQueryDocumentsDifferentDate(mapper, new Date(2014 - 1900, 4, 5).getTime()));
    getQueryStore().save(TestUtils.TEST_TABLE_NAME, documents);
    for(Document document : documents) {
        getElasticsearchConnection().getClient()
                .admin()
                .indices()
                .prepareRefresh(ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, document.getTimestamp()))
                .execute()
                .actionGet();
    }
    GetIndexResponse response = getElasticsearchConnection().getClient()
            .admin()
            .indices()
            .getIndex(new GetIndexRequest())
            .actionGet();
    // Find all indices returned for this table name.. (using regex to match)
    assertEquals(3, Arrays.stream(response.getIndices())
            .filter(index -> index.matches(".*-" + TestUtils.TEST_TABLE_NAME + "-.*"))
            .count());

    Query query = new Query();
    query.setLimit(documents.size());
    query.setTable(TestUtils.TEST_TABLE_NAME);
    BetweenFilter betweenFilter = new BetweenFilter();
    betweenFilter.setField("_timestamp");
    betweenFilter.setFrom(documents.get(0)
                                  .getTimestamp());
    betweenFilter.setTo(documents.get(documents.size() - 1)
                                .getTimestamp());
    betweenFilter.setTemporal(true);
    query.setFilters(Lists.<Filter>newArrayList(betweenFilter));
    QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query));
    assertEquals(documents.size(), actualResponse.getDocuments()
            .size());
}
 
Example #5
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showIndexType_onlyOneTypeReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
    String query = String.format("show %s/account", TEST_INDEX_ACCOUNT);
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    ImmutableOpenMap<String, MappingMetadata> typeToData = mappings.get(TEST_INDEX_ACCOUNT);
    Assert.assertEquals(1,typeToData.size());
}
 
Example #6
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showIndex_onlyOneIndexReturWithMoreThanOneTypes() throws SqlParseException, SQLFeatureNotSupportedException {
    String query = "show " + TEST_INDEX + "*";
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    Assert.assertTrue(mappings.size()>1);
}
 
Example #7
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showIndex_onlyOneIndexReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
    String query = "show "+ TEST_INDEX_ACCOUNT;
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    Assert.assertEquals(1, mappings.size());
    Assert.assertTrue(mappings.containsKey(TEST_INDEX_ACCOUNT));

}
 
Example #8
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showAll_atLeastOneIndexReturns() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
    String query = "show *";
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    Assert.assertTrue(mappings.size() >= 1);

}
 
Example #9
Source File: GetIndexRequestRestListener.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Override
public RestResponse buildResponse(GetIndexResponse getIndexResponse, XContentBuilder builder) throws Exception {
    GetIndexRequest.Feature[] features = getIndexRequest.features();
    String[] indices = getIndexResponse.indices();

    builder.startObject();
    for (String index : indices) {
        builder.startObject(index);
        for (GetIndexRequest.Feature feature : features) {
            switch (feature) {
                case ALIASES:
                    writeAliases(getIndexResponse.aliases().get(index), builder, channel.request());
                    break;
                case MAPPINGS:
                    writeMappings(getIndexResponse.mappings().get(index), builder, channel.request());
                    break;
                case SETTINGS:
                    writeSettings(getIndexResponse.settings().get(index), builder, channel.request());
                    break;
                default:
                    throw new IllegalStateException("feature [" + feature + "] is not valid");
            }
        }
        builder.endObject();

    }
    builder.endObject();

    return new BytesRestResponse(RestStatus.OK, builder);
}
 
Example #10
Source File: PluginClient.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
public GetIndexResponse getIndices(String... indices) throws InterruptedException, ExecutionException {
    return execute(new Callable<GetIndexResponse>() {

        @Override
        public GetIndexResponse call() throws Exception {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Getting indices '{}'", StringUtils.join(indices, ", "));
            }
            GetIndexRequestBuilder builder = client.admin().indices().prepareGetIndex().setIndices(indices);
            return builder.get();
        }
        
    });
}
 
Example #11
Source File: IndexServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> show(String indexName) throws IOException {
    GetIndexRequest request = new GetIndexRequest();
    request.indices(indexName);
    GetIndexResponse getIndexResponse = elasticsearchRestTemplate.getClient()
            .indices().get(request, RequestOptions.DEFAULT);
    ImmutableOpenMap<String, MappingMetaData> mappOpenMap = getIndexResponse.getMappings().get(indexName);
    List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get(indexName);

    String settingsStr = getIndexResponse.getSettings().get(indexName).toString();
    Object settingsObj = null;
    if (StrUtil.isNotEmpty(settingsStr)) {
        settingsObj = JSONObject.parse(settingsStr);
    }
    Map<String, Object> result = new HashMap<>(1);
    Map<String, Object> indexMap = new HashMap<>(3);
    Map<String, Object> mappMap = new HashMap<>(mappOpenMap.size());
    List<String> aliasesList = new ArrayList<>(indexAliases.size());
    indexMap.put("aliases", aliasesList);
    indexMap.put("settings", settingsObj);
    indexMap.put("mappings", mappMap);
    result.put(indexName, indexMap);
    //获取mappings数据
    for (ObjectCursor<String> key : mappOpenMap.keys()) {
        MappingMetaData data = mappOpenMap.get(key.value);
        Map<String, Object> dataMap = data.getSourceAsMap();
        mappMap.put(key.value, dataMap);
    }
    //获取aliases数据
    for (AliasMetaData aliases : indexAliases) {
        aliasesList.add(aliases.getAlias());
    }
    return result;
}
 
Example #12
Source File: ElasticIndexManager.java    From cicada with MIT License 5 votes vote down vote up
private List<String> getAllIndice() {
  final List<String> indice = new LinkedList<String>();
  final GetIndexResponse resp = client.admin().indices().getIndex(new GetIndexRequest()).actionGet();

  for (final String indexName : resp.indices()) {
    if (indexName.startsWith(props.getEsSpanIndexPrefix()) //
        || indexName.startsWith(props.getEsAnnotationIndexPrefix())) {
      indice.add(indexName);
    }
  }

  return indice;
}
 
Example #13
Source File: KPIDataLoader.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if KPI's elasticsearch Index and Type exists
 */
public KPIDataLoader assertESTypesExists()
{
	final IndicesAdminClient admin = elasticsearchClient.admin()
			.indices();

	//
	// Check index exists
	final String esSearchIndex = kpi.getESSearchIndex();
	final GetIndexResponse indexResponse = admin.prepareGetIndex()
			.addIndices(esSearchIndex)
			.get();
	final List<String> indexesFound = Arrays.asList(indexResponse.getIndices());
	if (!indexesFound.contains(esSearchIndex))
	{
		throw new AdempiereException("ES index '" + esSearchIndex + "' not found in " + indexesFound);
	}
	logger.debug("Indexes found: {}", indexesFound);

	//
	// Check type exists
	final String esTypes = kpi.getESSearchTypes();
	final boolean esTypesExists = admin.prepareTypesExists(esSearchIndex)
			.setTypes(kpi.getESSearchTypes())
			.get()
			.isExists();
	if (!esTypesExists)
	{
		throw new AdempiereException("Elasticseatch types " + esTypes + " does not exist");
	}

	// All good
	return this;
}
 
Example #14
Source File: Elasticsearch5Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example #15
Source File: Elasticsearch6Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example #16
Source File: Elasticsearch2Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    //----es scher error --
    Thread.currentThread().setName("getTable_001");
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example #17
Source File: AbstractESTest.java    From elasticsearch-migration with Apache License 2.0 5 votes vote down vote up
@SneakyThrows
protected boolean checkIndexExists(String indexName) {
    final ActionFuture<GetIndexResponse> response = client.admin().indices().getIndex(new GetIndexRequest().indices(indexName));

    try {
        return response.get() != null;
    } catch (ExecutionException e) {
        return false;
    }
}
 
Example #18
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void getIndex(GetIndexRequest request, ActionListener<GetIndexResponse> listener) {
    execute(GetIndexAction.INSTANCE, request, listener);
}
 
Example #19
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<GetIndexResponse> getIndex(GetIndexRequest request) {
    return execute(GetIndexAction.INSTANCE, request);
}
 
Example #20
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 4 votes vote down vote up
private GetIndexResponse runShowQuery(String query) throws SqlParseException, SQLFeatureNotSupportedException {
    SearchDao searchDao = MainTestSuite.getSearchDao();
    SqlElasticRequestBuilder requestBuilder =  searchDao.explain(query).explain();
    return (GetIndexResponse) requestBuilder.get();
}
 
Example #21
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Get index metadata for particular indices.
 *
 * @param request  The index aliases request
 * @param listener A listener to be notified with a result
 */
void getIndex(GetIndexRequest request, ActionListener<GetIndexResponse> listener);
 
Example #22
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Get index metadata for particular indices.
 *
 * @param request The result future
 */
ActionFuture<GetIndexResponse> getIndex(GetIndexRequest request);