-
Couldn't load subscription status.
- Fork 1
feat: add nested aggregation #174
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
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2016923
feat: add nested aggregation
ada-krupa 2defdfe
chore: improvements
ada-krupa fa7b531
chore: improvements
ada-krupa c63e4d6
fix: update response for missing value aggregation
ada-krupa 6b7fe3a
feat: updated release action
przemyslawwalczak 69b319e
chore: updated release it configuration
przemyslawwalczak 65b97b0
chore: release v1.20.0
78b8ef5
Merge branch 'main' into feat/nested-aggs
ada-krupa c980d79
chore: improvements
ada-krupa 0390cab
chore: improvements
ada-krupa 6f20c92
chore: improvements
ada-krupa 2585341
chore: improvements
ada-krupa d4b4060
chore: improvements
ada-krupa 17a30c4
chore: improvements
ada-krupa 7d18b02
chore: improvements
ada-krupa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { HomeDocument } from 'test/module' | ||
| import { TEST_ELASTICSEARCH_NODE } from 'test/constants' | ||
| import { setupNestApplication } from 'test/toolkit' | ||
| import { ElasticsearchModule } from 'module/elasticsearch.module' | ||
| import { ElasticsearchService } from 'module/elasticsearch.service' | ||
| import { getNestedAggregation } from './get-nested' | ||
|
|
||
| describe('getNestedAggregation', () => { | ||
| const { app } = setupNestApplication({ | ||
| imports: [ | ||
| ElasticsearchModule.register({ | ||
| node: TEST_ELASTICSEARCH_NODE | ||
| }) | ||
| ] | ||
| }) | ||
|
|
||
| it('accepts only an array of objects schema field', () => { | ||
| const query = getNestedAggregation<HomeDocument>('animals') | ||
|
|
||
| expect(query).toEqual({ | ||
| nested: { | ||
| path: 'animals' | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| it('should query elasticsearch for nested aggregation ', async () => { | ||
| const service = app.get(ElasticsearchService) | ||
|
|
||
| const result = await service.search(HomeDocument, { | ||
| size: 0, | ||
| aggregations: { | ||
| nestedAggregation: getNestedAggregation('animals') | ||
| } | ||
| }) | ||
|
|
||
| expect(result.aggregations.nestedAggregation.doc_count).toBeDefined() | ||
| expect(result.aggregations.nestedAggregation.doc_count).not.toEqual(0) | ||
| }) | ||
|
|
||
| it('should return doc_count 0 after passing string field which is not an array of objects type', async () => { | ||
| const service = app.get(ElasticsearchService) | ||
|
|
||
| const result = await service.search(HomeDocument, { | ||
| size: 0, | ||
| aggregations: { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| nestedAggregation: getNestedAggregation('address' as any) | ||
| } | ||
| }) | ||
|
|
||
| expect(result.aggregations.nestedAggregation.doc_count).toBeDefined() | ||
| expect(result.aggregations.nestedAggregation.doc_count).toEqual(0) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Document, ArrayOfObjectsField } from 'lib/common' | ||
|
|
||
| export type NestedAggregationBody<TDocument extends Document> = { | ||
| path: ArrayOfObjectsField<TDocument> | ||
| } | ||
|
|
||
| export type NestedAggregation<TDocument extends Document> = { | ||
| nested: NestedAggregationBody<TDocument> | ||
| } | ||
|
|
||
| export const getNestedAggregation = <TDocument extends Document>(path: ArrayOfObjectsField<TDocument>): NestedAggregation<TDocument> => ({ | ||
| nested: { | ||
| path | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './search' | ||
| export * from './cluster-health' | ||
| export * from './missing-value-aggregation' | ||
| export * from './nested-aggregation' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export type NestedAggregationResponse = { | ||
| doc_count: number | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { IsString } from 'class-validator' | ||
|
|
||
| export class AnimalDocument { | ||
| @IsString() | ||
| readonly id: string | ||
|
|
||
| @IsString() | ||
| readonly type: string | ||
|
|
||
| @IsString() | ||
| readonly color: string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './home.document' | ||
| export * from './enums' | ||
| export * from './test.service' | ||
| export * from './animal.document' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.