Skip to content

[7.x] [ML] [Data Frame] nesting group_by fields like other aggs (#42718) #42760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ public void testPreviewTransform() throws Exception {

config += " \"pivot\": {"
+ " \"group_by\": {"
+ " \"reviewer\": {\"terms\": { \"field\": \"user_id\" }},"
+ " \"user.id\": {\"terms\": { \"field\": \"user_id\" }},"
+ " \"by_day\": {\"date_histogram\": {\"fixed_interval\": \"1d\",\"field\":\"timestamp\",\"format\":\"yyyy-MM-dd\"}}},"
+ " \"aggregations\": {"
+ " \"avg_rating\": {"
+ " \"user.avg_rating\": {"
+ " \"avg\": {"
+ " \"field\": \"stars\""
+ " } } } }"
Expand All @@ -265,10 +265,14 @@ public void testPreviewTransform() throws Exception {
List<Map<String, Object>> preview = (List<Map<String, Object>>)previewDataframeResponse.get("preview");
// preview is limited to 100
assertThat(preview.size(), equalTo(100));
Set<String> expectedFields = new HashSet<>(Arrays.asList("reviewer", "by_day", "avg_rating"));
Set<String> expectedTopLevelFields = new HashSet<>(Arrays.asList("user", "by_day"));
Set<String> expectedNestedFields = new HashSet<>(Arrays.asList("id", "avg_rating"));
preview.forEach(p -> {
Set<String> keys = p.keySet();
assertThat(keys, equalTo(expectedFields));
assertThat(keys, equalTo(expectedTopLevelFields));
Map<String, Object> nestedObj = (Map<String, Object>)p.get("user");
keys = nestedObj.keySet();
assertThat(keys, equalTo(expectedNestedFields));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Stream<Map<String, Object>> extractCompositeAggregationResults(Com
groups.getGroups().keySet().forEach(destinationFieldName -> {
Object value = bucket.getKey().get(destinationFieldName);
idGen.add(destinationFieldName, value);
document.put(destinationFieldName, value);
updateDocument(document, destinationFieldName, value);
});

List<String> aggNames = aggregationBuilders.stream().map(AggregationBuilder::getName).collect(Collectors.toList());
Expand Down