Make sure PutMappingRequest accepts content types other than JSON. (#37720)

This commit is contained in:
Julie Tibshirani 2019-01-23 08:51:05 -08:00 committed by GitHub
parent 647e225698
commit f0fc6e8003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 16 deletions

View File

@ -254,7 +254,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
* The mapping source definition.
*/
public PutMappingRequest source(XContentBuilder mappingBuilder) {
return source(Strings.toString(mappingBuilder), mappingBuilder.contentType());
return source(BytesReference.bytes(mappingBuilder), mappingBuilder.contentType());
}
/**
@ -264,7 +264,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(mappingSource);
return source(Strings.toString(builder), XContentType.JSON);
return source(BytesReference.bytes(builder), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e);
}

View File

@ -23,7 +23,6 @@ import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -135,20 +134,8 @@ public class PutMappingRequestTests extends ESTestCase {
String type = randomAlphaOfLength(5);
request.type(type);
request.source(randomMapping());
request.source(RandomCreateIndexGenerator.randomMapping());
return request;
}
private static XContentBuilder randomMapping() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
if (randomBoolean()) {
RandomCreateIndexGenerator.randomMappingFields(builder, true);
}
builder.endObject();
return builder;
}
}