Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.
This repository was archived by the owner on Sep 22, 2025. It is now read-only.

forceMapping does not work on a multinode cluster #13

@iskytek

Description

@iskytek

spring config:

  <bean id="esNode"
        class="fr.pilato.spring.elasticsearch.ElasticsearchNodeFactoryBean">
    </bean>

    <bean id="esClient"
        class="fr.pilato.spring.elasticsearch.ElasticsearchClientFactoryBean" >
        <property name="mappings">
            <list>
                <value>twitter/tweet</value>
                <value>rss/feed</value>
                <value>rss/config</value>
            </list>
        </property>
        <property name="aliases">
            <list>
                <value>alltheworld:twitter</value>
                <value>alltheworld:rss</value>
            </list>
        </property>
        <property name="forceMapping" value="true" />
    </bean>

ElasticsearchAbstractClientFactoryBean method:

private void pushMapping(String index, String type, boolean force, boolean merge) throws Exception {
        if (logger.isTraceEnabled()) logger.trace("pushMapping("+index+","+type+","+force+")");

        checkClient();

        // If type already exists and if we are in force mode, we delete the type and its mapping
        if (force && isMappingExist(index, type)) {
            if (logger.isDebugEnabled()) logger.debug("Force remove old type and mapping ["+index+"]/["+type+"]");
            // Remove mapping and type in ElasticSearch !
            client.admin().indices()
                .prepareDeleteMapping(index)
                .setType(type)
                .execute().actionGet();

             Thread.sleep(500); // for now, we don't have ack logic, so just wait

        }

        // If type does not exist, we create it
        boolean mappingExist = isMappingExist(index, type);           
              // If  not sleep , here is always true 

        if (merge || !mappingExist) {
            if (logger.isDebugEnabled()) {
                if (mappingExist) {
                    logger.debug("Updating mapping ["+index+"]/["+type+"].");
                } else {
                    logger.debug("Mapping ["+index+"]/["+type+"] doesn't exist. Creating it.");
                }
            }
            // Read the mapping json file if exists and use it
            String source = readMapping(index, type);
            if (source != null) {
                if (logger.isTraceEnabled()) logger.trace("Mapping for ["+index+"]/["+type+"]="+source);
                // Create type and mapping
                PutMappingResponse response = client.admin().indices()
                    .preparePutMapping(index)
                    .setType(type)
                    .setSource(source)
                    .execute().actionGet();         
                if (!response.acknowledged()) {
                    throw new Exception("Could not define mapping for type ["+index+"]/["+type+"].");
                } else {
                    if (logger.isDebugEnabled()) {
                        if (mappingExist) {
                            logger.debug("Mapping definition for ["+index+"]/["+type+"] succesfully merged.");
                        } else {
                            logger.debug("Mapping definition for ["+index+"]/["+type+"] succesfully created.");
                        }
                    }
                }
            } else {
                if (logger.isDebugEnabled()) logger.debug("No mapping definition for ["+index+"]/["+type+"]. Ignoring.");
            }
        } else {
            if (logger.isDebugEnabled()) logger.debug("Mapping ["+index+"]/["+type+"] already exists and mergeMapping is not set.");
        }
        if (logger.isTraceEnabled()) logger.trace("/pushMapping("+index+","+type+","+force+")");
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions