Skip to content

Commit

Permalink
[ML-Dataframe] Use standard string constant for mapping type (#39453)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle authored Feb 28, 2019
1 parent 0cf7982 commit 6b5efb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public static IndexTemplateMetaData getIndexTemplateMetaData() throws IOExceptio
// the configurations are expected to be small
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1"))
// todo: remove type
.putMapping(MapperService.SINGLE_MAPPING_NAME, Strings.toString(mappings()))
.build();
return dataFrameTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.Map.Entry;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;

public final class DataframeIndex {
private static final Logger logger = LogManager.getLogger(DataframeIndex.class);

public static final String DOC_TYPE = "_doc";
private static final String PROPERTIES = "properties";
private static final String TYPE = "type";
private static final String META = "_meta";
Expand All @@ -44,7 +44,7 @@ public static void createDestinationIndex(Client client, DataFrameTransformConfi
request.settings(Settings.builder() // <1>
.put("index.number_of_shards", 1).put("index.number_of_replicas", 0));

request.mapping(DOC_TYPE, createMappingXContent(mappings, transformConfig.getId()));
request.mapping(SINGLE_MAPPING_NAME, createMappingXContent(mappings, transformConfig.getId()));

client.execute(CreateIndexAction.INSTANCE, request, ActionListener.wrap(createIndexResponse -> {
listener.onResponse(true);
Expand All @@ -59,14 +59,14 @@ public static void createDestinationIndex(Client client, DataFrameTransformConfi
private static XContentBuilder createMappingXContent(Map<String, String> mappings, String id) {
try {
XContentBuilder builder = jsonBuilder().startObject();
builder.startObject(DOC_TYPE);
builder.startObject(SINGLE_MAPPING_NAME);
addMetaData(builder, id);
builder.startObject(PROPERTIES);
for (Entry<String, String> field : mappings.entrySet()) {
builder.startObject(field.getKey()).field(TYPE, field.getValue()).endObject();
}
builder.endObject(); // properties
builder.endObject(); // doc_type
builder.endObject(); // _doc type
return builder.endObject();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 6b5efb8

Please sign in to comment.