Skip to content

Commit

Permalink
remove type from PutMappingRequest.buildFromSimplifiedDef
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Mar 4, 2022
1 parent 6441ea6 commit 6cf60d9
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
"my_feature_field",
"type=rank_feature",
"my_negative_feature_field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,14 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
docType,
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
docType,
queryField,
"type=percolator",
aliasField,
"type=alias,path=" + queryField
)
PutMappingRequest.buildFromSimplifiedDef(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField)
)
),
MapperService.MergeReason.MAPPING_UPDATE
);
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(docType, TEXT_FIELD_NAME, "type=text"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(TEXT_FIELD_NAME, "type=text"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
super.initializeAdditionalMappings(mapperService);
mapperService.merge(
"_doc",
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc", "some_nested_object", "type=nested"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("some_nested_object", "type=nested"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public CreateIndexRequest mapping(String type, Map<String, ?> source) {
*/
@Deprecated
public CreateIndexRequest mapping(String type, Object... source) {
mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source));
mapping(type, PutMappingRequest.buildFromSimplifiedDef(source));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public String source() {
* 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));
return source(buildFromSimplifiedDef(source));
}

public String origin() {
Expand All @@ -232,16 +232,14 @@ public PutMappingRequest origin(String origin) {
}

/**
* @param type
* the mapping type
* @param source
* consisting of field/properties pairs (e.g. "field1",
* "type=string,store=true")
* @throws IllegalArgumentException
* 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 buildFromSimplifiedDef(Object... source) {
if (source.length % 2 != 0) {
throw new IllegalArgumentException("mapping source must be pairs of fieldnames and properties definition.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public PutIndexTemplateRequest mapping(String type, Map<String, Object> source)
* ("field1", "type=string,store=true").
*/
public PutIndexTemplateRequest mapping(String type, Object... source) {
mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source));
mapping(type, PutMappingRequest.buildFromSimplifiedDef(source));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public void testValidation() {
}

/**
* Test that {@link PutMappingRequest#buildFromSimplifiedDef(String, Object...)}
* Test that {@link PutMappingRequest#buildFromSimplifiedDef(Object...)}
* rejects inputs where the {@code Object...} varargs of field name and properties are not
* paired correctly
*/
public void testBuildFromSimplifiedDef() {
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> PutMappingRequest.buildFromSimplifiedDef("type", "only_field")
() -> PutMappingRequest.buildFromSimplifiedDef("only_field")
);
assertEquals("mapping source must be pairs of fieldnames and properties definition.", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
INTEGER_RANGE_FIELD_NAME,
"type=integer_range",
LONG_RANGE_FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
"string_boost",
"type=text",
"string_no_pos",
"type=text,index_options=docs"
)
PutMappingRequest.buildFromSimplifiedDef("string_boost", "type=text", "string_no_pos", "type=text,index_options=docs")
)
),
MapperService.MergeReason.MAPPING_UPDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
TEXT_FIELD_NAME,
"type=text",
INT_FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ public void testDisabledFieldNamesField() throws Exception {
.merge(
"_doc",
new CompressedXContent(
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc", "foo", "type=text", "_field_names", "enabled=false"))
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=false"))
),
MapperService.MergeReason.MAPPING_UPDATE
);
Expand All @@ -1091,9 +1091,7 @@ public void testDisabledFieldNamesField() throws Exception {
.merge(
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef("_doc", "foo", "type=text", "_field_names", "enabled=true")
)
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=true"))
),
MapperService.MergeReason.MAPPING_UPDATE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
String docType = "_doc";
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(docType, "m_s_m", "type=long"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("m_s_m", "type=long"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ public void onRemoval(ShardId shardId, Accountable accountable) {
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
TEXT_FIELD_NAME,
"type=text",
KEYWORD_FIELD_NAME,
Expand Down

0 comments on commit 6cf60d9

Please sign in to comment.