Skip to content

Commit

Permalink
fix filter for value
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Jan 29, 2020
1 parent 2bad957 commit 1f43f73
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const createFilter = (key: string, value: string | null | undefined) =>
value != null
import { esFilters } from '../../../../../../../../src/plugins/data/public';

export const createFilter = (
key: string,
value: string[] | string | null | undefined
): esFilters.Filter => {
const queryValue = value != null ? (Array.isArray(value) ? value[0] : value) : null;
return queryValue != null
? {
meta: {
alias: null,
negate: false,
disabled: false,
type: 'phrase',
key,
value,
value: queryValue,
params: {
query: value,
query: queryValue,
},
},
query: {
match: {
[key]: {
query: value,
query: queryValue,
type: 'phrase',
},
},
},
}
: {
: ({
exists: {
field: key,
},
Expand All @@ -39,4 +45,5 @@ export const createFilter = (key: string, value: string | null | undefined) =>
type: 'exists',
value: 'exists',
},
};
} as esFilters.Filter);
};

0 comments on commit 1f43f73

Please sign in to comment.