Search in sources :

Example 1 with GetIndexResponse

use of org.elasticsearch.client.indices.GetIndexResponse in project gora by apache.

the class ElasticsearchStoreMetadataAnalyzer method getTablesNames.

@Override
public List<String> getTablesNames() throws GoraException {
    GetIndexRequest request = new GetIndexRequest("*");
    GetIndexResponse response;
    try {
        response = elasticsearchClient.indices().get(request, RequestOptions.DEFAULT);
    } catch (IOException ex) {
        throw new GoraException(ex);
    }
    if (response == null) {
        LOG.error("Could not find indices.");
        throw new GoraException("Could not find indices.");
    }
    return Arrays.asList(response.getIndices());
}
Also used : GoraException(org.apache.gora.util.GoraException) GetIndexResponse(org.elasticsearch.client.indices.GetIndexResponse) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) IOException(java.io.IOException)

Example 2 with GetIndexResponse

use of org.elasticsearch.client.indices.GetIndexResponse in project gora by apache.

the class ElasticsearchStoreMetadataAnalyzer method getTableInfo.

@Override
public ElasticsearchStoreCollectionMetadata getTableInfo(String tableName) throws GoraException {
    GetIndexRequest request = new GetIndexRequest(tableName);
    GetIndexResponse getIndexResponse;
    try {
        getIndexResponse = elasticsearchClient.indices().get(request, RequestOptions.DEFAULT);
    } catch (IOException ex) {
        throw new GoraException(ex);
    }
    MappingMetadata indexMappings = getIndexResponse.getMappings().get(tableName);
    Map<String, Object> indexKeysAndTypes = (Map<String, Object>) indexMappings.getSourceAsMap().get("properties");
    List<String> documentTypes = new ArrayList<>();
    List<String> documentKeys = new ArrayList<>();
    for (Map.Entry<String, Object> entry : indexKeysAndTypes.entrySet()) {
        Map<String, Object> subEntry = (Map<String, Object>) entry.getValue();
        documentTypes.add((String) subEntry.get("type"));
        documentKeys.add(entry.getKey());
    }
    ElasticsearchStoreCollectionMetadata collectionMetadata = new ElasticsearchStoreCollectionMetadata();
    collectionMetadata.setDocumentKeys(documentKeys);
    collectionMetadata.setDocumentTypes(documentTypes);
    return collectionMetadata;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) GoraException(org.apache.gora.util.GoraException) GetIndexResponse(org.elasticsearch.client.indices.GetIndexResponse) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)2 GoraException (org.apache.gora.util.GoraException)2 GetIndexRequest (org.elasticsearch.client.indices.GetIndexRequest)2 GetIndexResponse (org.elasticsearch.client.indices.GetIndexResponse)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MappingMetadata (org.elasticsearch.cluster.metadata.MappingMetadata)1