use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest 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());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest 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;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest in project datashare by ICIJ.
the class ElasticsearchConfiguration method createIndex.
public static boolean createIndex(RestHighLevelClient client, String indexName) {
GetIndexRequest request = new GetIndexRequest(indexName);
try {
if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
LOGGER.info("index {} does not exist, creating one", indexName);
CreateIndexRequest createReq = new CreateIndexRequest(indexName);
createReq.settings(getResourceContent(SETTINGS_RESOURCE_NAME), JSON);
createReq.mapping(getResourceContent(MAPPING_RESOURCE_NAME), JSON);
client.indices().create(createReq, RequestOptions.DEFAULT);
return true;
}
} catch (IOException e) {
throw new ConfigurationException(e);
}
return false;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest in project datashare by ICIJ.
the class ElasticsearchRule method before.
@Override
protected void before() throws Throwable {
GetIndexRequest request = new GetIndexRequest(indexName);
if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
CreateIndexRequest createReq = new CreateIndexRequest(indexName);
byte[] settings = toByteArray(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(SETTINGS_RESOURCE_NAME)));
createReq.settings(new String(settings), JSON);
byte[] mapping = toByteArray(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(MAPPING_RESOURCE_NAME)));
createReq.mapping(new String(mapping), JSON);
client.indices().create(createReq, RequestOptions.DEFAULT);
}
}
Aggregations