public static Map<String, ?> getMappingSource(final MutableTable table) { if (table.getColumnByName(FIELD_ID) == null) { final MutableColumn idColumn = new MutableColumn(FIELD_ID, ColumnType.STRING).setTable(table).setPrimaryKey( true); table.addColumn(0, idColumn); } final Map<String, Map<String, String>> propertiesMap = new LinkedHashMap<>(); for (Column column : table.getColumns()) { final String columnName = column.getName(); if (FIELD_ID.equals(columnName)) { // do nothing - the ID is a client-side construct continue; } final String fieldName = getValidatedFieldName(columnName); final Map<String, String> propertyMap = new HashMap<>(); final String type = getType(column); propertyMap.put("type", type); propertiesMap.put(fieldName, propertyMap); } HashMap<String, Map<String, Map<String, String>>> docTypeMap = new HashMap<>(); docTypeMap.put("properties", propertiesMap); final Map<String, Map<String, Map<String, Map<String, String>>>> mapping = new HashMap<>(); mapping.put(table.getName(), docTypeMap); return mapping; }
public static Map<String, ?> getMappingSource(final MutableTable table) { if (table.getColumnByName(FIELD_ID) == null) { final MutableColumn idColumn = new MutableColumn(FIELD_ID, ColumnType.STRING).setTable(table).setPrimaryKey( true); table.addColumn(0, idColumn); } final Map<String, Map<String, String>> propertiesMap = new LinkedHashMap<>(); for (Column column : table.getColumns()) { final String columnName = column.getName(); if (FIELD_ID.equals(columnName)) { // do nothing - the ID is a client-side construct continue; } final String fieldName = getValidatedFieldName(columnName); final Map<String, String> propertyMap = new HashMap<>(); final String type = getType(column); propertyMap.put("type", type); propertiesMap.put(fieldName, propertyMap); } HashMap<String, Map<String, Map<String, String>>> docTypeMap = new HashMap<>(); docTypeMap.put("properties", propertiesMap); final Map<String, Map<String, Map<String, Map<String, String>>>> mapping = new HashMap<>(); mapping.put(table.getName(), docTypeMap); return mapping; }
@Override public void execute() throws MetaModelException { final ElasticSearchRestUpdateCallback updateCallback = getUpdateCallback(); final ElasticSearchRestDataContext dataContext = updateCallback.getDataContext(); final String indexName = dataContext.getIndexName(); final String documentType = getTable().getName(); final Map<String, Object> source = new HashMap<>(); final Column[] columns = getColumns(); final Object[] values = getValues(); String id = null; for (int i = 0; i < columns.length; i++) { if (isSet(columns[i])) { final String columnName = columns[i].getName(); final Object value = values[i]; if (ElasticSearchUtils.FIELD_ID.equals(columnName)) { if (value != null) { id = value.toString(); } } else { final String fieldName = ElasticSearchUtils.getValidatedFieldName(columnName); source.put(fieldName, value); } } } assert !source.isEmpty(); IndexRequest indexRequest = new IndexRequest(indexName, documentType, id); indexRequest.source(source); getUpdateCallback().execute(indexRequest); }