diff --git a/.changeset/hungry-pigs-love.md b/.changeset/hungry-pigs-love.md new file mode 100644 index 000000000..f70df6372 --- /dev/null +++ b/.changeset/hungry-pigs-love.md @@ -0,0 +1,5 @@ +--- +'contexture-elasticsearch': minor +--- + +capbility of dealing with `null` ranges added to `step` query on elastic search provider diff --git a/packages/provider-elasticsearch/src/example-types/filters/step.js b/packages/provider-elasticsearch/src/example-types/filters/step.js index 34fbfc43f..a5233f50d 100644 --- a/packages/provider-elasticsearch/src/example-types/filters/step.js +++ b/packages/provider-elasticsearch/src/example-types/filters/step.js @@ -7,39 +7,26 @@ const getMinAndMax = (range) => { return { min, max } } -const isValueMaxOnSteps = (value, steps) => { - const max = steps[steps.length - 1] - return value === max -} - -let filter = ({ field, range, steps }) => { +let filter = ({ field, range }) => { const { min, max } = getMinAndMax(range) - - /** In the last step, we do not filter by the upper bound */ - if (isValueMaxOnSteps(max, steps)) { - return { - range: { [field]: pickSafeNumbers({ gte: min }) }, - } - } - return { range: { [field]: pickSafeNumbers({ gte: min, lte: max }) }, } } -let buildQuery = (field, range, steps) => { +let buildQuery = (field, range) => { return { aggs: { rangeFilter: { - filter: filter({ field, range, steps }), + filter: filter({ field, range }), }, }, } } let result = async (node, search) => { - let { field, range, steps } = node - const result = await search(buildQuery(field, range, steps)) + let { field, range } = node + const result = await search(buildQuery(field, range)) const recordsCount = result.aggregations.rangeFilter.doc_count return { recordsCount } } diff --git a/packages/provider-elasticsearch/src/example-types/filters/step.test.js b/packages/provider-elasticsearch/src/example-types/filters/step.test.js index 631f091bb..d892e9aaf 100644 --- a/packages/provider-elasticsearch/src/example-types/filters/step.test.js +++ b/packages/provider-elasticsearch/src/example-types/filters/step.test.js @@ -21,10 +21,10 @@ describe('step', () => { expect(filter(input)).toEqual(expectedValue) }) - it('removes upper bound when range is last step', () => { + it('removes upper bound when upper bound is null', () => { const inputWithNewRange = { ...input, - range: [0, 1000], + range: [0, null], } let expectedValue = { range: { test: { gte: 0 } } } expect(filter(inputWithNewRange)).toEqual(expectedValue) @@ -38,7 +38,7 @@ describe('step', () => { }, }, } - let output = buildQuery(input.field, input.range, input.steps) + let output = buildQuery(input.field, input.range) expect(output).toEqual(expectedDSL) }) })