use of org.springframework.data.elasticsearch.core.index.Settings in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getTemplateData.
// endregion
// region templates
@Nullable
public static TemplateData getTemplateData(GetIndexTemplatesResponse getIndexTemplatesResponse, String templateName) {
for (IndexTemplateMetadata indexTemplateMetadata : getIndexTemplatesResponse.getIndexTemplates()) {
if (indexTemplateMetadata.name().equals(templateName)) {
Settings settings = new Settings();
org.elasticsearch.common.settings.Settings templateSettings = indexTemplateMetadata.settings();
templateSettings.keySet().forEach(key -> settings.put(key, templateSettings.get(key)));
Map<String, AliasData> aliases = new LinkedHashMap<>();
ImmutableOpenMap<String, AliasMetadata> aliasesResponse = indexTemplateMetadata.aliases();
Iterator<String> keysIt = aliasesResponse.keysIt();
while (keysIt.hasNext()) {
String key = keysIt.next();
aliases.put(key, ResponseConverter.toAliasData(aliasesResponse.get(key)));
}
return //
TemplateData.builder().withIndexPatterns(indexTemplateMetadata.patterns().toArray(new String[0])).withSettings(//
settings).withMapping(//
Document.from(indexTemplateMetadata.mappings().getSourceAsMap())).withAliases(//
aliases).withOrder(//
indexTemplateMetadata.order()).withVersion(indexTemplateMetadata.version()).build();
}
}
return null;
}
use of org.springframework.data.elasticsearch.core.index.Settings in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method settingsFromGetIndexResponse.
/**
* extract the index settings information from a given index
*
* @param getIndexResponse the elastic GetIndexResponse
* @param indexName the index name
* @return a document that represents {@link Settings}
*/
private static Settings settingsFromGetIndexResponse(GetIndexResponse getIndexResponse, String indexName) {
Settings settings = new Settings();
org.elasticsearch.common.settings.Settings indexSettings = getIndexResponse.getSettings().get(indexName);
if (!indexSettings.isEmpty()) {
for (String key : indexSettings.keySet()) {
settings.put(key, indexSettings.get(key));
}
}
return settings;
}
use of org.springframework.data.elasticsearch.core.index.Settings in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getIndexInformations.
/**
* get the index informations from a {@link org.elasticsearch.action.admin.indices.get.GetIndexResponse} (transport
* client)
*
* @param getIndexResponse the index response, must not be {@literal null}
* @return list of {@link IndexInformation}s for the different indices
*/
public static List<IndexInformation> getIndexInformations(org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse) {
List<IndexInformation> indexInformationList = new ArrayList<>();
for (String indexName : getIndexResponse.getIndices()) {
Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
}
return indexInformationList;
}
use of org.springframework.data.elasticsearch.core.index.Settings in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldGetTemplate.
// DATAES-612
@Test
void shouldGetTemplate() throws JSONException {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
org.springframework.data.elasticsearch.core.document.Document mapping = indexOps.createMapping(TemplateClass.class).block();
Settings settings = indexOps.createSettings(TemplateClass.class).block();
AliasActions aliasActions = new AliasActions(new AliasAction.Add(AliasActionParameters.builderForTemplate().withAliases("alias1", "alias2").build()));
PutTemplateRequest putTemplateRequest = //
PutTemplateRequest.builder("test-template", "log-*").withSettings(//
settings).withMappings(//
mapping).withAliasActions(//
aliasActions).withOrder(//
11).withVersion(//
42).build();
Boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
assertThat(acknowledged).isTrue();
GetTemplateRequest getTemplateRequest = new GetTemplateRequest(putTemplateRequest.getName());
TemplateData templateData = indexOps.getTemplate(getTemplateRequest).block();
assertThat(templateData).isNotNull();
assertThat(templateData.getIndexPatterns()).containsExactlyInAnyOrder(putTemplateRequest.getIndexPatterns());
assertEquals(settings.toJson(), templateData.getSettings().toJson(), false);
assertEquals(mapping.toJson(), templateData.getMapping().toJson(), false);
Map<String, AliasData> aliases = templateData.getAliases();
assertThat(aliases).hasSize(2);
AliasData alias1 = aliases.get("alias1");
assertThat(alias1.getAlias()).isEqualTo("alias1");
AliasData alias2 = aliases.get("alias2");
assertThat(alias2.getAlias()).isEqualTo("alias2");
assertThat(templateData.getOrder()).isEqualTo(putTemplateRequest.getOrder());
assertThat(templateData.getVersion()).isEqualTo(putTemplateRequest.getVersion());
}
use of org.springframework.data.elasticsearch.core.index.Settings in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getIndexInformations.
// endregion
// region index informations
/**
* get the index informations from a {@link GetIndexResponse}
*
* @param getIndexResponse the index response, must not be {@literal null}
* @return list of {@link IndexInformation}s for the different indices
*/
public static List<IndexInformation> getIndexInformations(GetIndexResponse getIndexResponse) {
Assert.notNull(getIndexResponse, "getIndexResponse must not be null");
List<IndexInformation> indexInformationList = new ArrayList<>();
for (String indexName : getIndexResponse.getIndices()) {
Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
}
return indexInformationList;
}
Aggregations