Skip to content

Commit f4c38e1

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 53c2c22 commit f4c38e1

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
@@ -612,23 +612,67 @@ describe('withDomainFilter', () => {
612612
});
613613
});
614614

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

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

633677
describe('nested domain paths', () => {
634678
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)