Skip to content
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

Make sure that field collapsing supports field aliases. #32648

Merged
merged 1 commit into from
Aug 7, 2018
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
@@ -1,7 +1,14 @@
setup:
- do:
indices.create:
index: test
index: test
body:
mappings:
test:
properties:
numeric_group: { type: integer }
group_alias: { type: alias, path: numeric_group }

- do:
index:
index: test
Expand Down Expand Up @@ -341,3 +348,25 @@ setup:
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._version: 55 }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._version: 44 }

---
"field collapsing on a field alias":
- skip:
version: " - 6.99.99"
reason: The associated bugfix is pending backport to 6.x.
- do:
search:
index: test
body:
collapse: { field: group_alias, inner_hits: { name: sub_hits } }
sort: [{ sort: desc }]

- match: { hits.total: 6 }
- length: { hits.hits: 3 }

- match: { hits.hits.0.fields.group_alias: [3] }
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1}
- match: { hits.hits.1.fields.group_alias: [1] }
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 3}
- match: { hits.hits.2.fields.group_alias: [25] }
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 2}
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ public CollapseContext build(SearchContext context) {
+ field + "`, " + "only indexed field can retrieve `inner_hits`");
}

return new CollapseContext(fieldType, innerHits);
return new CollapseContext(field, fieldType, innerHits);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,29 @@
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.query.InnerHitBuilder;

import java.util.Collections;
import java.util.List;

/**
* Context used for field collapsing
*/
public class CollapseContext {
private final String fieldName;
private final MappedFieldType fieldType;
private final List<InnerHitBuilder> innerHits;

public CollapseContext(MappedFieldType fieldType, InnerHitBuilder innerHit) {
public CollapseContext(String fieldName,
MappedFieldType fieldType,
List<InnerHitBuilder> innerHits) {
this.fieldName = fieldName;
this.fieldType = fieldType;
this.innerHits = Collections.singletonList(innerHit);
this.innerHits = innerHits;
}

public CollapseContext(MappedFieldType fieldType, List<InnerHitBuilder> innerHits) {
this.fieldType = fieldType;
this.innerHits = innerHits;
/**
* The requested field name to collapse on.
*/
public String getFieldName() {
return fieldName;
}

/** The field type used for collapsing **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept

if (context.collapse() != null) {
// retrieve the `doc_value` associated with the collapse field
String name = context.collapse().getFieldType().name();
String name = context.collapse().getFieldName();
if (context.docValueFieldsContext() == null) {
context.docValueFieldsContext(new DocValueFieldsContext(
Collections.singletonList(new FieldAndFormat(name, DocValueFieldsContext.USE_DEFAULT_FORMAT))));
Expand Down