Skip to content
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

[Maps] fix creating filter from array fields #119548

Merged
merged 3 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,40 @@ describe('getESFilters', () => {
]);
});

test('Should return phrase filters when field value is an array', async () => {
const esTooltipProperty = new ESTooltipProperty(
new TooltipProperty(featurePropertyField.getName(), await featurePropertyField.getLabel(), [
'my value',
'my other value',
]),
indexPattern,
featurePropertyField,
APPLY_GLOBAL_QUERY
);
expect(await esTooltipProperty.getESFilters()).toEqual([
{
meta: {
index: 'indexPatternId',
},
query: {
match_phrase: {
['machine.os']: 'my value',
},
},
},
{
meta: {
index: 'indexPatternId',
},
query: {
match_phrase: {
['machine.os']: 'my other value',
},
},
},
]);
});

test('Should return NOT exists filter for null values', async () => {
const esTooltipProperty = new ESTooltipProperty(
new TooltipProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ export class ESTooltipProperty implements ITooltipProperty {
return [];
}

const value = this.getRawValue();
if (value == null) {
const rawValue = this.getRawValue();
if (rawValue == null) {
const existsFilter = esFilters.buildExistsFilter(indexPatternField, this._indexPattern);
existsFilter.meta.negate = true;
return [existsFilter];
} else {
return [esFilters.buildPhraseFilter(indexPatternField, value as string, this._indexPattern)];
const values = Array.isArray(rawValue) ? (rawValue as string[]) : [rawValue as string];
return values.map((value) => {
return esFilters.buildPhraseFilter(indexPatternField, value, this._indexPattern);
});
}
}
}