From a6b2f8cc0c60491e847d01306fd21dc5928ee9bf Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Wed, 17 Jul 2019 11:11:43 -0600 Subject: [PATCH 1/3] Remove nested array in ES Query DSL generation --- .../ast_to_es_query_dsl.test.js.snap | 113 +++++++++++------- .../search_bar/query/ast_to_es_query_dsl.js | 2 +- .../query/ast_to_es_query_dsl.test.js | 7 ++ 3 files changed, 77 insertions(+), 45 deletions(-) diff --git a/src/components/search_bar/query/__snapshots__/ast_to_es_query_dsl.test.js.snap b/src/components/search_bar/query/__snapshots__/ast_to_es_query_dsl.test.js.snap index 7c95c0c9f77..c4b26e75c51 100644 --- a/src/components/search_bar/query/__snapshots__/ast_to_es_query_dsl.test.js.snap +++ b/src/components/search_bar/query/__snapshots__/ast_to_es_query_dsl.test.js.snap @@ -207,36 +207,63 @@ Object { Object { "bool": Object { "should": Array [ - Array [ - Object { - "bool": Object { - "must": Array [ - Object { - "match": Object { - "name": Object { - "operator": "and", - "query": "john", - }, + Object { + "bool": Object { + "must": Array [ + Object { + "match": Object { + "name": Object { + "operator": "and", + "query": "john", }, }, - ], - }, + }, + ], }, - Object { - "bool": Object { - "must": Array [ - Object { - "match": Object { - "name": Object { - "operator": "and", - "query": "fred", - }, + }, + Object { + "bool": Object { + "must": Array [ + Object { + "match": Object { + "name": Object { + "operator": "and", + "query": "fred", }, }, - ], - }, + }, + ], }, - ], + }, + ], + }, + }, + ], + }, +} +`; + +exports[`astToEsQueryDsl ast - (name:john) 1`] = ` +Object { + "bool": Object { + "must": Array [ + Object { + "bool": Object { + "should": Array [ + Object { + "bool": Object { + "must": Array [ + Object { + "match": Object { + "name": Object { + "operator": "and", + "query": "john", + }, + }, + }, + ], + }, + }, ], }, }, @@ -385,30 +412,28 @@ Object { Object { "bool": Object { "should": Array [ - Array [ - Object { - "bool": Object { - "must": Array [ - Object { - "term": Object { - "enrolled": true, - }, + Object { + "bool": Object { + "must": Array [ + Object { + "term": Object { + "enrolled": true, }, - ], - }, + }, + ], }, - Object { - "bool": Object { - "must": Array [ - Object { - "simple_query_string": Object { - "query": "Teacher", - }, + }, + Object { + "bool": Object { + "must": Array [ + Object { + "simple_query_string": Object { + "query": "Teacher", }, - ], - }, + }, + ], }, - ], + }, ], }, }, diff --git a/src/components/search_bar/query/ast_to_es_query_dsl.js b/src/components/search_bar/query/ast_to_es_query_dsl.js index 7645a74f677..acb69606108 100644 --- a/src/components/search_bar/query/ast_to_es_query_dsl.js +++ b/src/components/search_bar/query/ast_to_es_query_dsl.js @@ -302,7 +302,7 @@ export const astToEsQueryDsl = (ast, options) => { must.push({ bool: { - should: [clauses.map(clause => ({ bool: clause }))], + should: clauses.map(clause => ({ bool: clause })), }, }); return must; diff --git a/src/components/search_bar/query/ast_to_es_query_dsl.test.js b/src/components/search_bar/query/ast_to_es_query_dsl.test.js index 2f169f299bf..dd03a5e6159 100644 --- a/src/components/search_bar/query/ast_to_es_query_dsl.test.js +++ b/src/components/search_bar/query/ast_to_es_query_dsl.test.js @@ -138,6 +138,13 @@ describe('astToEsQueryDsl', () => { expect(query).toMatchSnapshot(); }); + test('ast - (name:john)', () => { + const query = astToEsQueryDsl( + AST.create([AST.Group.must([AST.Field.must.eq('name', 'john')])]) + ); + expect(query).toMatchSnapshot(); + }); + test('ast - (name:john OR name:fred)', () => { const query = astToEsQueryDsl( AST.create([ From 002ab691ef0980efcc2b490c388a04fe387801ee Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Wed, 17 Jul 2019 11:14:55 -0600 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17201b3d117..1848f80d2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fixed `EuiComboBox`'s options list from staying open when scrolled in a container by auto-closing the list on scroll ([#2106](https://github.com/elastic/eui/pull/2106)) - Fixed content provided to `EuiListGroupItem` and `EuiFilterButton` `title` attribute to prevent unreadable popover ([#2100](https://github.com/elastic/eui/pull/2100)) - Fixed a nearly infinite `requestAnimationFrame` loop caused by `focus` state changes in nested `EuiPopover` components ([#2110](https://github.com/elastic/eui/pull/2110)) +- Fixed incorrect ES Query DSL generated by `EuiSearchBar` when an OR clause is present ([#2133](https://github.com/elastic/eui/pull/2110)) ## [`12.3.1`](https://github.com/elastic/eui/tree/v12.3.1) From 480dfc5d354058207985279d43f5154cb096c169 Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Wed, 17 Jul 2019 11:22:14 -0600 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1848f80d2b7..81a25f11f04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - Fixed `EuiComboBox`'s options list from staying open when scrolled in a container by auto-closing the list on scroll ([#2106](https://github.com/elastic/eui/pull/2106)) - Fixed content provided to `EuiListGroupItem` and `EuiFilterButton` `title` attribute to prevent unreadable popover ([#2100](https://github.com/elastic/eui/pull/2100)) - Fixed a nearly infinite `requestAnimationFrame` loop caused by `focus` state changes in nested `EuiPopover` components ([#2110](https://github.com/elastic/eui/pull/2110)) -- Fixed incorrect ES Query DSL generated by `EuiSearchBar` when an OR clause is present ([#2133](https://github.com/elastic/eui/pull/2110)) +- Fixed incorrect ES Query DSL generated by `EuiSearchBar` when an OR clause is present ([#2133](https://github.com/elastic/eui/pull/2133)) ## [`12.3.1`](https://github.com/elastic/eui/tree/v12.3.1)