Make sure that field collapsing supports field aliases. (#32648)
This commit is contained in:
parent
8bfb0f3f8d
commit
d7183f8f3d
|
@ -2,6 +2,13 @@ setup:
|
|||
- do:
|
||||
indices.create:
|
||||
index: test
|
||||
body:
|
||||
mappings:
|
||||
test:
|
||||
properties:
|
||||
numeric_group: { type: integer }
|
||||
group_alias: { type: alias, path: numeric_group }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
|
@ -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}
|
||||
|
|
|
@ -247,6 +247,6 @@ public class CollapseBuilder implements Writeable, ToXContentObject {
|
|||
+ field + "`, " + "only indexed field can retrieve `inner_hits`");
|
||||
}
|
||||
|
||||
return new CollapseContext(fieldType, innerHits);
|
||||
return new CollapseContext(field, fieldType, innerHits);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,26 +25,31 @@ import org.elasticsearch.index.mapper.MappedFieldType;
|
|||
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) {
|
||||
this.fieldType = fieldType;
|
||||
this.innerHits = Collections.singletonList(innerHit);
|
||||
}
|
||||
|
||||
public CollapseContext(MappedFieldType fieldType, List<InnerHitBuilder> innerHits) {
|
||||
public CollapseContext(String fieldName,
|
||||
MappedFieldType fieldType,
|
||||
List<InnerHitBuilder> innerHits) {
|
||||
this.fieldName = fieldName;
|
||||
this.fieldType = fieldType;
|
||||
this.innerHits = innerHits;
|
||||
}
|
||||
|
||||
/**
|
||||
* The requested field name to collapse on.
|
||||
*/
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
/** The field type used for collapsing **/
|
||||
public MappedFieldType getFieldType() {
|
||||
return fieldType;
|
||||
|
|
|
@ -61,7 +61,7 @@ public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|||
|
||||
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))));
|
||||
|
|
Loading…
Reference in New Issue