Skip to content

Commit 56a649a

Browse files
siddhant1Siddhantgitar-bot
authored andcommitted
add domain query ES fix (#26037)
* add domain query ES * test: add coverage for non-bool clause extraction in DomainUtils Co-authored-by: siddhant1 <siddhant1@users.noreply.github.com> --------- Co-authored-by: Siddhant <siddhant@MacBook-Pro-2.local> Co-authored-by: Gitar <noreply@gitar.ai> Co-authored-by: siddhant1 <siddhant1@users.noreply.github.com>
1 parent 4b632cb commit 56a649a

2 files changed

Lines changed: 92 additions & 39 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/utils/DomainUtils.test.tsx

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -611,23 +611,67 @@ describe('withDomainFilter', () => {
611611
});
612612
});
613613

614-
it('should preserve existing params when adding query_filter', () => {
615-
mockGetPathName.mockReturnValue('/api/search');
616-
mockGetState.mockReturnValue({ activeDomain: 'engineering' });
617-
618-
const config = createMockConfig('get', '/search/query', {
619-
index: SearchIndex.TABLE,
620-
limit: 10,
621-
offset: 0,
614+
it('should preserve existing params when adding query_filter', () => {
615+
mockGetPathName.mockReturnValue('/api/search');
616+
mockGetState.mockReturnValue({ activeDomain: 'engineering' });
617+
618+
const config = createMockConfig('get', '/search/query', {
619+
index: SearchIndex.TABLE,
620+
limit: 10,
621+
offset: 0,
622+
});
623+
const result = withDomainFilter(config);
624+
625+
expect(result.params).toHaveProperty('index', SearchIndex.TABLE);
626+
expect(result.params).toHaveProperty('limit', 10);
627+
expect(result.params).toHaveProperty('offset', 0);
628+
expect(result.params).toHaveProperty('query_filter');
622629
});
623-
const result = withDomainFilter(config);
624630

625-
expect(result.params).toHaveProperty('index', SearchIndex.TABLE);
626-
expect(result.params).toHaveProperty('limit', 10);
627-
expect(result.params).toHaveProperty('offset', 0);
628-
expect(result.params).toHaveProperty('query_filter');
631+
it('should preserve non-bool top-level clauses when adding domain filter', () => {
632+
mockGetPathName.mockReturnValue('/api/search');
633+
mockGetState.mockReturnValue({ activeDomain: 'engineering' });
634+
635+
const existingFilter = JSON.stringify({
636+
query: {
637+
term: { 'some.field': 'someValue' },
638+
bool: { must: [{ term: { 'other.field': 'otherValue' } }] },
639+
},
640+
});
641+
642+
const config = createMockConfig('get', '/search/query', {
643+
index: SearchIndex.TABLE,
644+
query_filter: existingFilter,
645+
});
646+
const result = withDomainFilter(config);
647+
648+
const parsed = JSON.parse(result.params?.query_filter as string);
649+
650+
expect(parsed.query.bool.must).toContainEqual({
651+
term: { 'some.field': 'someValue' },
652+
});
653+
expect(parsed.query.bool.must).toContainEqual({
654+
term: { 'other.field': 'otherValue' },
655+
});
656+
expect(parsed.query.bool.must).toContainEqual({
657+
bool: {
658+
should: [
659+
{
660+
term: {
661+
'domains.fullyQualifiedName': 'engineering',
662+
},
663+
},
664+
{
665+
prefix: {
666+
'domains.fullyQualifiedName': 'engineering.',
667+
},
668+
},
669+
],
670+
},
671+
});
672+
expect(parsed.query.bool.must).toHaveLength(3);
673+
});
629674
});
630-
});
631675

632676
describe('nested domain paths', () => {
633677
it('should handle nested domain paths correctly', () => {

openmetadata-ui/src/main/resources/ui/src/utils/DomainUtils.tsx

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,42 @@ export const withDomainFilter = (
101101
}
102102
}
103103

104-
const mustArray = Array.isArray(filter.query?.bool?.must)
105-
? filter.query.bool.must
106-
: filter.query?.bool?.must
107-
? [filter.query.bool.must]
108-
: [];
109-
110-
filter.query.bool = {
111-
...filter.query?.bool,
112-
must: [
113-
...mustArray,
114-
{
115-
bool: {
116-
should: [
117-
{
118-
term: {
119-
'domains.fullyQualifiedName': activeDomain,
104+
let mustArray: QueryFieldInterface[] = [];
105+
const existingMust = filter.query?.bool?.must;
106+
if (Array.isArray(existingMust)) {
107+
mustArray = [...existingMust];
108+
} else if (existingMust) {
109+
mustArray = [existingMust];
110+
}
111+
112+
const { bool: existingBool, ...nonBoolClauses } = filter.query ?? {};
113+
for (const [key, value] of Object.entries(nonBoolClauses)) {
114+
mustArray.push({ [key]: value } as QueryFieldInterface);
115+
}
116+
117+
filter.query = {
118+
bool: {
119+
...existingBool,
120+
must: [
121+
...mustArray,
122+
{
123+
bool: {
124+
should: [
125+
{
126+
term: {
127+
'domains.fullyQualifiedName': activeDomain,
128+
},
120129
},
121-
},
122-
{
123-
prefix: {
124-
'domains.fullyQualifiedName': `${activeDomain}.`,
130+
{
131+
prefix: {
132+
'domains.fullyQualifiedName': `${activeDomain}.`,
133+
},
125134
},
126-
},
127-
],
128-
},
129-
} as QueryFieldInterface,
130-
],
135+
],
136+
},
137+
} as QueryFieldInterface,
138+
],
139+
},
131140
};
132141

133142
config.params = {

0 commit comments

Comments
 (0)