Thanks to visit codestin.com
Credit goes to github.com

Skip to content
1 change: 1 addition & 0 deletions src/components/Utils/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const nestedHistogramQueryStrForEachField = (mainField, numericAggAsText) => (`
}
termsFields {
field
count
terms {
key
count
Expand Down
8 changes: 8 additions & 0 deletions src/server/es/__tests__/aggs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
termsFields: [
{
field: 'gender',
count: 41,
terms: [
{
key: 'male',
Expand All @@ -948,6 +949,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
},
{
field: 'someNonExistingField',
count: 0,
terms: [
{
key: null,
Expand All @@ -963,6 +965,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
termsFields: [
{
field: 'gender',
count: 35,
terms: [
{
key: 'male',
Expand All @@ -980,6 +983,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
},
{
field: 'someNonExistingField',
count: 0,
terms: [
{
key: null,
Expand Down Expand Up @@ -1027,6 +1031,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
termsFields: [
{
field: 'gender',
count: 41,
terms: [
{
key: 'male',
Expand All @@ -1044,6 +1049,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
},
{
field: 'someNonExistingField',
count: 0,
terms: [
{
key: null,
Expand All @@ -1069,6 +1075,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
termsFields: [
{
field: 'gender',
count: 35,
terms: [
{
key: 'male',
Expand All @@ -1086,6 +1093,7 @@ describe('could only aggregate to find missing fields (both existing and non-exi
},
{
field: 'someNonExistingField',
count: 0,
terms: [
{
key: null,
Expand Down
2 changes: 2 additions & 0 deletions src/server/es/aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ const processResultsForNestedAgg = (nestedAggFields, item, resultObj) => {
const tempResult = {};
tempResult.field = element;
tempResult.terms = [];
tempResult.count = 0;
const variableName = `${element}Terms`;
if (item[variableName].buckets && item[variableName].buckets.length > 0) {
item[variableName].buckets.forEach((itemElement) => {
tempResult.terms.push({
key: itemElement.key,
count: itemElement.doc_count,
});
tempResult.count += itemElement.doc_count;
});
} else {
tempResult.terms.push({
Expand Down
1 change: 1 addition & 0 deletions src/server/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export const buildSchemaString = (esConfig, esInstance) => {
const nestedTermsFieldsBucketSchema = `
type BucketsForNestedTermsFields {
field: String
count: Int
terms: [BucketsForString]
}
`;
Expand Down