// Path: connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/ESIndexType.java
// public enum ESIndexType {
//     /**
//      * No Index.
//      */
//     NO("no"),
//     /**
//      * Analyzed Index.
//      */
//     ANALYZED("analyzed"),
//     /**
//      * Not analized index.
//      */
//     NOT_ANALYZED("not_analyzed");
// 
//     /**
//      * The code.
//      */
//     private final String code;
// 
//     /**
//      * Cosntructor.
//      *
//      * @param code the code.
//      */
//     ESIndexType(String code) {
//         this.code = code;
//     }
// 
//     /**
//      * Return the default index value.
//      *
//      * @return the default index value.
//      */
//     public static ESIndexType getDefault() {
//         return ANALYZED;
//     }
// 
//     /**
//      * Return Index code.
//      *
//      * @return the index code.
//      */
//     public String getCode() {
//         return code;
//     }
// 
// }


import java.util.List;
import java.util.Map;
import com.stratio.connector.elasticsearch.core.engine.metadata.ESIndexType;
import com.stratio.crossdata.common.data.ColumnName;
import com.stratio.crossdata.common.exceptions.ExecutionException;
import com.stratio.crossdata.common.metadata.ColumnMetadata;
import com.stratio.crossdata.common.metadata.ColumnType;
import com.stratio.crossdata.common.metadata.TableMetadata;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
                for (String analyzer : analyzers) {
                    xContentBuilder.startObject(analyzer);
                    xContentBuilder = xContentBuilder.field(TYPE, columnTypeName);
                    xContentBuilder = xContentBuilder.field(ANALYZER, analyzer);
                    xContentBuilder.endObject();
                }
                xContentBuilder.endObject();
            }
        }

        return xContentBuilder.endObject();
    }


    /**
     * This method creates the XContenBuilder that defines a mapping for a specific index and type.
     *
     * @param columnMetadata the column meta data.
     * @return the XContentBuilder.
     * @throws IOException        if a IO excetion happens.
     * @throws ExecutionException if an error happen.
     */
    public XContentBuilder addColumn(ColumnMetadata columnMetadata) throws IOException, ExecutionException {
        XContentBuilder mapping;

        // Adds the information about the index and type
        mapping = XContentFactory.jsonBuilder().startObject()
                .startObject(columnMetadata.getName().getTableName().getName()).startObject(PROPERTIES)
                .startObject(columnMetadata.getName().getName())
                .field(TYPE, TypeConverter.convert(columnMetadata.getColumnType()))
// Path: connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/ESIndexType.java
// public enum ESIndexType {
//     /**
//      * No Index.
//      */
//     NO("no"),
//     /**
//      * Analyzed Index.
//      */
//     ANALYZED("analyzed"),
//     /**
//      * Not analized index.
//      */
//     NOT_ANALYZED("not_analyzed");
// 
//     /**
//      * The code.
//      */
//     private final String code;
// 
//     /**
//      * Cosntructor.
//      *
//      * @param code the code.
//      */
//     ESIndexType(String code) {
//         this.code = code;
//     }
// 
//     /**
//      * Return the default index value.
//      *
//      * @return the default index value.
//      */
//     public static ESIndexType getDefault() {
//         return ANALYZED;
//     }
// 
//     /**
//      * Return Index code.
//      *
//      * @return the index code.
//      */
//     public String getCode() {
//         return code;
//     }
// 
// }


// Path: connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/utils/ContentBuilderCreator.java
import java.util.List;
import java.util.Map;
import com.stratio.connector.elasticsearch.core.engine.metadata.ESIndexType;
import com.stratio.crossdata.common.data.ColumnName;
import com.stratio.crossdata.common.exceptions.ExecutionException;
import com.stratio.crossdata.common.metadata.ColumnMetadata;
import com.stratio.crossdata.common.metadata.ColumnType;
import com.stratio.crossdata.common.metadata.TableMetadata;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;

                for (String analyzer : analyzers) {
                    xContentBuilder.startObject(analyzer);
                    xContentBuilder = xContentBuilder.field(TYPE, columnTypeName);
                    xContentBuilder = xContentBuilder.field(ANALYZER, analyzer);
                    xContentBuilder.endObject();
                }
                xContentBuilder.endObject();
            }
        }

        return xContentBuilder.endObject();
    }


    /**
     * This method creates the XContenBuilder that defines a mapping for a specific index and type.
     *
     * @param columnMetadata the column meta data.
     * @return the XContentBuilder.
     * @throws IOException        if a IO excetion happens.
     * @throws ExecutionException if an error happen.
     */
    public XContentBuilder addColumn(ColumnMetadata columnMetadata) throws IOException, ExecutionException {
        XContentBuilder mapping;

        // Adds the information about the index and type
        mapping = XContentFactory.jsonBuilder().startObject()
                .startObject(columnMetadata.getName().getTableName().getName()).startObject(PROPERTIES)
                .startObject(columnMetadata.getName().getName())
                .field(TYPE, TypeConverter.convert(columnMetadata.getColumnType()))
                .field(INDEX, ESIndexType.getDefault().getCode()).endObject().endObject().endObject()