RollOver API - Add Mapping


(Fabricio Archanjo) #1

Hi everyone,

I'm trying to create a service to rollover an index to me, but before to rollover I have to copy my setting and mapping to add a new index to be created.

Basically:
I'm getting a primary mapping:

GetMappingsResponse response = client.admin()
    .indices()
    .prepareGetMappings(getIndexFormat(roll.getAlias()))
    .execute().actionGet();

Then,

response.getMappings().get(getIndexFormat(roll.getAlias()))
        .forEach(objectCursor -> {
            try {
                objectCursor.value.getSourceAsMap().entrySet()
                        .forEach(entry -> {
                            builder.mapping(objectCursor.value.type(), String.valueOf(entry.getValue()));
                        });
            } catch (Exception e) {
                logger.warn("addMapping", e);
            }
        });

This is my Request RollOver builder:

RolloverRequestBuilder builder = client.admin().indices()
.prepareRolloverIndex(roll.getAlias())
.addMaxIndexDocsCondition(roll.getDocument())
.dryRun(true)
.addMaxIndexSizeCondition(new ByteSizeValue(roll.getSize(),
        roll.getUnit()))
.waitForActiveShards(1);

I know its a wrong way, but rollover builder api only accept (String type, String source), how can I convert it to (String type, String source) ?

I have tried too many things and always getting.

mapping source must be pairs of fieldnames and properties definition


(Fabricio Archanjo) #2

someone?


(Christian Dahlqvist) #3

I would recommend applying mappings through an index template instead. That way it will automatically be applied when rollover generates a new index. This is shown in this blog post.


(Fabricio Archanjo) #4