|
|
@@ -172,8 +172,8 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
|
|
* Also supports metadata mapping fields such as `_all` and `_parent` as property definition, these metadata
|
|
|
* mapping fields will automatically be put on the top level mapping object.
|
|
|
*/
|
|
|
- public PutMappingRequest source(Object... source) {
|
|
|
- return source(buildFromSimplifiedDef(MapperService.SINGLE_MAPPING_NAME, source));
|
|
|
+ public PutMappingRequest source(String... source) {
|
|
|
+ return source(simpleMapping(source));
|
|
|
}
|
|
|
|
|
|
public String origin() {
|
|
|
@@ -187,8 +187,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param type
|
|
|
- * the mapping type
|
|
|
* @param source
|
|
|
* consisting of field/properties pairs (e.g. "field1",
|
|
|
* "type=string,store=true")
|
|
|
@@ -196,22 +194,19 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
|
|
* if the number of the source arguments is not divisible by two
|
|
|
* @return the mappings definition
|
|
|
*/
|
|
|
- public static XContentBuilder buildFromSimplifiedDef(String type, Object... source) {
|
|
|
+ public static XContentBuilder simpleMapping(String... source) {
|
|
|
if (source.length % 2 != 0) {
|
|
|
throw new IllegalArgumentException("mapping source must be pairs of fieldnames and properties definition.");
|
|
|
}
|
|
|
try {
|
|
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
|
builder.startObject();
|
|
|
- if (type != null) {
|
|
|
- builder.startObject(type);
|
|
|
- }
|
|
|
|
|
|
for (int i = 0; i < source.length; i++) {
|
|
|
- String fieldName = source[i++].toString();
|
|
|
+ String fieldName = source[i++];
|
|
|
if (RESERVED_FIELDS.contains(fieldName)) {
|
|
|
builder.startObject(fieldName);
|
|
|
- String[] s1 = Strings.splitStringByCommaToArray(source[i].toString());
|
|
|
+ String[] s1 = Strings.splitStringByCommaToArray(source[i]);
|
|
|
for (String s : s1) {
|
|
|
String[] s2 = Strings.split(s, "=");
|
|
|
if (s2.length != 2) {
|
|
|
@@ -225,13 +220,13 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
|
|
|
|
|
builder.startObject("properties");
|
|
|
for (int i = 0; i < source.length; i++) {
|
|
|
- String fieldName = source[i++].toString();
|
|
|
+ String fieldName = source[i++];
|
|
|
if (RESERVED_FIELDS.contains(fieldName)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
builder.startObject(fieldName);
|
|
|
- String[] s1 = Strings.splitStringByCommaToArray(source[i].toString());
|
|
|
+ String[] s1 = Strings.splitStringByCommaToArray(source[i]);
|
|
|
for (String s : s1) {
|
|
|
String[] s2 = Strings.split(s, "=");
|
|
|
if (s2.length != 2) {
|
|
|
@@ -242,9 +237,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
|
|
builder.endObject();
|
|
|
}
|
|
|
builder.endObject();
|
|
|
- if (type != null) {
|
|
|
- builder.endObject();
|
|
|
- }
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
} catch (Exception e) {
|