From 0404ad00c08cb439fc48227231e4653db92e29dd Mon Sep 17 00:00:00 2001 From: dawn023349 <64775829+dawn023349@users.noreply.github.com> Date: Mon, 16 Jan 2023 01:11:41 +0900 Subject: [PATCH 1/2] [Dashboard] Fix Phrase_filter query for scripted fields (#148942) - ISSUE [Dashboard] Visualize Library doesn't work filter on scripted fields of Array Type. #148942 --- .../kbn-es-query/src/filters/build_filters/phrase_filter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts b/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts index 3bbf94cd0722a..4adc8fdc0fdd4 100644 --- a/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts @@ -148,7 +148,7 @@ export const buildInlineScriptForPhraseFilter = (scriptedField: DataViewFieldBas // We must wrap painless scripts in a lambda in case they're more than a simple expression if (scriptedField.lang === 'painless') { return ( - `boolean compare(Supplier s, def v) {return s.get() == v;}` + + `boolean compare(Supplier s, def v) {if(s.get() instanceof List){List list = s.get(); for(def k : list){if(k==v){return true;}}return false;}else{return s.get() == v;}}` + `compare(() -> { ${scriptedField.script} }, params.value);` ); } else { From 52007384986c36d5901cb3aab266a20310ff37ee Mon Sep 17 00:00:00 2001 From: dawn023349 <64775829+dawn023349@users.noreply.github.com> Date: Mon, 23 Jan 2023 23:04:44 +0900 Subject: [PATCH 2/2] [Dashboard] Update phrase_filter.test.ts Add to pull request for testing --- .../src/filters/build_filters/phrase_filter.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-es-query/src/filters/build_filters/phrase_filter.test.ts b/packages/kbn-es-query/src/filters/build_filters/phrase_filter.test.ts index 1088ba196840c..f2fc685b2e180 100644 --- a/packages/kbn-es-query/src/filters/build_filters/phrase_filter.test.ts +++ b/packages/kbn-es-query/src/filters/build_filters/phrase_filter.test.ts @@ -134,7 +134,7 @@ describe('buildInlineScriptForPhraseFilter', () => { }; const expected = - `boolean compare(Supplier s, def v) {return s.get() == v;}` + + `boolean compare(Supplier s, def v) {if(s.get() instanceof List){List list = s.get(); for(def k : list){if(k==v){return true;}}return false;}else{return s.get() == v;}}` + `compare(() -> { return foo; }, params.value);`; expect(buildInlineScriptForPhraseFilter(field)).toBe(expected);