Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"Create index with mappings":

- do:
indices.create:
index: test_index
body:
mappings:
properties:
field:
type: text

- do:
indices.get_mapping:
index: test_index

- is_true: test_index.mappings
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.elasticsearch.index.mapper.MapperService;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -290,13 +291,47 @@ else if (MapperService.SINGLE_MAPPING_NAME.equals(type) == false) {
}
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
source = fix((Map<String, Object>) source);
builder.map(source);
return mapping(Strings.toString(builder));
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
}

public Map<String, ?> fix(Map<String, Object> source) {
Map<String,Object> destination = new HashMap<>();
traverse(source,destination,null,false);
System.out.println(destination);
return destination;
}

private void traverse(Map<String, Object> current, Map<String, Object> destination, Map<String, Object> parent, boolean isWithinMultifield) {
for (Map.Entry<String, Object> entry : current.entrySet()) {
if (!(entry.getValue() instanceof Map)) {
destination.put(entry.getKey(), entry.getValue());
} else {
if(entry.getKey().equals("fields") ){
if(isWithinMultifield){
HashMap<String, Object> destination1 = new HashMap<>();
traverse((Map<String, Object>) entry.getValue(), destination1, parent, true);
parent.put(entry.getKey(),destination1);
}else{
HashMap<String, Object> destination1 = new HashMap<>();
traverse((Map<String, Object>) entry.getValue(), destination1, destination, true);
destination.put(entry.getKey(), destination1);

}
}else {
HashMap<String, Object> destination1 = new HashMap<>();
traverse((Map<String, Object>) entry.getValue(), destination1, destination, isWithinMultifield);
destination.put(entry.getKey(), destination1);
}
}
}

}

/**
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
Expand Down
Loading