Skip to content

Commit

Permalink
[Maps] fix creating filter from array fields (#119548)
Browse files Browse the repository at this point in the history
* [Maps] fix creating filter from array fields

* eslint

* remove unneeded cast
  • Loading branch information
nreese authored Nov 24, 2021
1 parent c56ede0 commit 7f2dbe5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
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);
});
}
}
}

0 comments on commit 7f2dbe5

Please sign in to comment.