forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG][Data] Support for custom filters with heterogeneous data fields
When enabling the advanced setting `courier:ignoreFilterIfFieldNotInIndex` Custom OpenSearch Query DSL filters could technically be applied to index patterns that map to indices that are not exactly the same. Since the custom query filter is a user input then users can really type anything that they need. Or any field that they know is present but we do not know for sure. Therefore, we can check if the id which is the index pattern title to check if we should apply the filter or not. Issue resolved: https://github.com/opensearch-project/dashboards-visualizations/issues/281 I believe issue: opensearch-project#5423 Should closed as that is expected functionality. Signed-off-by: Kawika Avilla <[email protected]>
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.test.ts
This file contains 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,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Filter } from '../filters'; | ||
import { customFilterMatchesIndex } from './custom_filter_matches_index'; | ||
import { IIndexPattern } from '../../index_patterns'; | ||
|
||
describe('customFilterMatchesIndex', () => { | ||
it('should return true if the custom filter has no meta', () => { | ||
const filter = {} as Filter; | ||
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IIndexPattern; | ||
|
||
expect(customFilterMatchesIndex(filter, indexPattern)).toBe(true); | ||
}); | ||
|
||
it('should return true if no index pattern is passed', () => { | ||
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter; | ||
|
||
expect(customFilterMatchesIndex(filter, undefined)).toBe(true); | ||
}); | ||
|
||
it('should return true if the custom filter has meta without a key', () => { | ||
const filter = { meta: { index: 'foo', type: 'custom' } } as Filter; | ||
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IIndexPattern; | ||
|
||
expect(customFilterMatchesIndex(filter, indexPattern)).toBe(true); | ||
}); | ||
|
||
it('should return false if the filter is not custom', () => { | ||
const filter = { meta: { index: 'foo', key: 'bar', type: 'match_all' } } as Filter; | ||
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IIndexPattern; | ||
|
||
expect(customFilterMatchesIndex(filter, indexPattern)).toBe(false); | ||
}); | ||
|
||
it('should return false if the custom filter is a different index id', () => { | ||
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter; | ||
const indexPattern = { id: 'bar', fields: [{ name: 'foo' }] } as IIndexPattern; | ||
|
||
expect(customFilterMatchesIndex(filter, indexPattern)).toBe(false); | ||
}); | ||
|
||
it('should return true if the custom filter is the same index id', () => { | ||
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter; | ||
const indexPattern = { id: 'foo', fields: [{ name: 'barf' }] } as IIndexPattern; | ||
|
||
expect(customFilterMatchesIndex(filter, indexPattern)).toBe(true); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts
This file contains 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,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IIndexPattern } from '../../index_patterns'; | ||
import { Filter } from '../filters'; | ||
|
||
export function customFilterMatchesIndex(filter: Filter, indexPattern?: IIndexPattern | null) { | ||
if (!filter.meta?.key || !indexPattern) { | ||
return true; | ||
} | ||
if (filter.meta?.type !== 'custom') { | ||
return false; | ||
} | ||
return filter.meta.index === indexPattern.id; | ||
} |
This file contains 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