-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
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: #5423 Should closed as that is expected functionality. Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
- Loading branch information
There are no files selected for viewing
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); | ||
}); | ||
}); |
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; | ||
Check warning on line 11 in src/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts Codecov / codecov/patchsrc/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts#L11
|
||
} | ||
if (filter.meta?.type !== 'custom') { | ||
return false; | ||
Check warning on line 14 in src/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts Codecov / codecov/patchsrc/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts#L14
|
||
} | ||
return filter.meta.index === indexPattern.id; | ||
Check warning on line 16 in src/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts Codecov / codecov/patchsrc/plugins/data/common/opensearch_query/opensearch_query/custom_filter_matches_index.ts#L16
|
||
} |