use of org.elasticsearch.client.indices.GetIndexRequest in project gora by apache.
the class ElasticsearchStore method createSchema.
@Override
public void createSchema() throws GoraException {
CreateIndexRequest request = new CreateIndexRequest(elasticsearchMapping.getIndexName());
Map<String, Object> properties = new HashMap<>();
for (Map.Entry<String, Field> entry : elasticsearchMapping.getFields().entrySet()) {
Map<String, Object> fieldType = new HashMap<>();
fieldType.put("type", entry.getValue().getDataType().getType().name().toLowerCase(Locale.ROOT));
if (entry.getValue().getDataType().getType() == Field.DataType.SCALED_FLOAT) {
fieldType.put("scaling_factor", entry.getValue().getDataType().getScalingFactor());
}
properties.put(entry.getKey(), fieldType);
}
// Special field for range query
properties.put("gora_id", new HashMap<String, Object>() {
{
put("type", "keyword");
}
});
Map<String, Object> mapping = new HashMap<>();
mapping.put("properties", properties);
request.mapping(mapping);
try {
if (!client.indices().exists(new GetIndexRequest(elasticsearchMapping.getIndexName()), RequestOptions.DEFAULT)) {
client.indices().create(request, RequestOptions.DEFAULT);
}
} catch (IOException ex) {
throw new GoraException(ex);
}
}
use of 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.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.elasticsearch.client.indices.GetIndexRequest in project sonarqube by SonarSource.
the class EsRequestDetailsTest method should_format_GetIndexRequest.
@Test
public void should_format_GetIndexRequest() {
GetIndexRequest request = new GetIndexRequest("index-1", "index-2");
assertThat(EsRequestDetails.computeDetailsAsString(request)).isEqualTo("ES indices exists request on indices 'index-1,index-2'");
}
use of org.elasticsearch.client.indices.GetIndexRequest in project sonarqube by SonarSource.
the class MigrationEsClientImpl method addMappingToExistingIndex.
@Override
public void addMappingToExistingIndex(String index, String type, String mappingName, String mappingType, Map<String, String> options) {
String[] indices = client.getIndex(new GetIndexRequest(index)).getIndices();
if (indices != null && indices.length == 1) {
Loggers.get(getClass()).info("Add mapping [{}] to Elasticsearch index [{}]", mappingName, index);
String mappingOptions = Stream.concat(Stream.of(Maps.immutableEntry("type", mappingType)), options.entrySet().stream()).map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(","));
client.putMapping(new PutMappingRequest(index).type(type).source(mappingName, mappingOptions));
updatedIndices.add(index);
} else {
throw new IllegalStateException("Expected only one index to be found, actual [" + String.join(",", indices) + "]");
}
}
Aggregations