Skip to content

Commit

Permalink
Make sure PutMappingRequest accepts content types other than JSON. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Jan 24, 2019
1 parent 9b0360d commit 40d0c17
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static XContentBuilder buildFromSimplifiedDef(String type, Object... sour
* The mapping source definition.
*/
public PutMappingRequest source(XContentBuilder mappingBuilder) {
return source(Strings.toString(mappingBuilder), mappingBuilder.contentType());
return source(BytesReference.bytes(mappingBuilder), mappingBuilder.contentType());
}

/**
Expand All @@ -266,7 +266,7 @@ public PutMappingRequest source(Map mappingSource) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -161,20 +160,8 @@ private static PutMappingRequest createTestItem() throws IOException {

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;
}
}

0 comments on commit 40d0c17

Please sign in to comment.