Example usage for com.amazonaws.services.cloudsearchv2.model OptionState RequiresIndexDocuments

List of usage examples for com.amazonaws.services.cloudsearchv2.model OptionState RequiresIndexDocuments

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudsearchv2.model OptionState RequiresIndexDocuments.

Prototype

OptionState RequiresIndexDocuments

To view the source code for com.amazonaws.services.cloudsearchv2.model OptionState RequiresIndexDocuments.

Click Source Link

Usage

From source file:com.clicktravel.infrastructure.persistence.aws.cloudsearch.manager.CloudSearchInfrastructureManager.java

License:Apache License

private void createCloudSearchDomain(final String domainName,
        final Collection<IndexDefinition> indexDefinitions) {
    final CreateDomainRequest createDomainRequest = new CreateDomainRequest().withDomainName(domainName);
    final CreateDomainResult createDomainResult = cloudSearchClient.createDomain(createDomainRequest);
    if (!createDomainResult.getDomainStatus().getCreated()) {
        throw new IllegalStateException(String.format("Domain with name %s failed to be created", domainName));
    }//  w  w  w  .  j a  v  a  2s . c o  m
    logger.debug("CloudSearch domain created: " + domainName);
    final Collection<IndexField> indexFields = indexDefinitionToIndexFieldCollectionMapper
            .map(indexDefinitions);
    for (final IndexField indexField : indexFields) {
        final DefineIndexFieldRequest defineIndexFieldRequest = new DefineIndexFieldRequest()
                .withDomainName(domainName).withIndexField(indexField);
        final DefineIndexFieldResult defineIndexFieldResult = cloudSearchClient
                .defineIndexField(defineIndexFieldRequest);
        if (OptionState.valueOf(defineIndexFieldResult.getIndexField().getStatus()
                .getState()) != OptionState.RequiresIndexDocuments) {
            throw new IllegalStateException(
                    String.format("Index with name %s failed to be created in domain %s",
                            indexField.getIndexFieldName(), domainName));
        }
        logger.debug("CloudSearch index created: " + domainName + "->" + indexField.getIndexFieldName());
    }
    final IndexDocumentsRequest indexDocumentsRequest = new IndexDocumentsRequest().withDomainName(domainName);
    cloudSearchClient.indexDocuments(indexDocumentsRequest);
    logger.debug("CloudSearch index rebuilding started for domain : " + domainName);
}