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 and dmlemeshko committed Nov 29, 2021
1 parent fcb7f20 commit dea2efa
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 dea2efa

Please sign in to comment.