From 126199a5ea0f372ff22b4928de6db4b4c3eca0ba Mon Sep 17 00:00:00 2001 From: delvedor Date: Mon, 7 Sep 2020 17:45:26 +0200 Subject: [PATCH] Updated test --- test/dsl/bool-optimize.test.ts | 538 ++++++++++++--------------- test/dsl/boolean-and-helpers.test.ts | 156 ++++---- test/dsl/boolean-not-helpers.test.ts | 110 +++--- test/dsl/boolean-or-helpers.test.ts | 112 +++--- test/dsl/fluent-query.test.ts | 138 +++---- test/dsl/query.test.ts | 150 ++++---- 6 files changed, 547 insertions(+), 657 deletions(-) diff --git a/test/dsl/bool-optimize.test.ts b/test/dsl/bool-optimize.test.ts index ac5aec7f9..9be96ab4e 100644 --- a/test/dsl/bool-optimize.test.ts +++ b/test/dsl/bool-optimize.test.ts @@ -20,17 +20,15 @@ test('must only query', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -60,21 +58,19 @@ test('must and must_not query', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { match: { 9: '10' } }, - { term: { 11: '12' } } - ], - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 13: '14' } }, - { term: { 15: '16' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { match: { 9: '10' } }, + { term: { 11: '12' } } + ], + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 13: '14' } }, + { term: { 15: '16' } } + ] } }) @@ -106,21 +102,19 @@ test('must and must_not query (mixed and nested)', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { match: { 9: '10' } }, - { term: { 11: '12' } }, - { term: { 15: '16' } } - ], - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 13: '14' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { match: { 9: '10' } }, + { term: { 11: '12' } }, + { term: { 15: '16' } } + ], + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 13: '14' } } + ] } }) @@ -140,17 +134,15 @@ test('must and should query', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - should: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + should: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ] } }) @@ -178,25 +170,23 @@ test('must and should query (nested) / 1', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { - bool: { - must: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ], - should: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { + bool: { + must: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ], + should: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } - ] - } + } + ] } }) @@ -222,25 +212,23 @@ test('must and should query (nested) / 2', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { - bool: { - must: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ], - should: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { + bool: { + must: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ], + should: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } - ] - } + } + ] } }) @@ -266,19 +254,17 @@ test('must and filter query / 1', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - filter: [ - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + filter: [ + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -302,19 +288,17 @@ test('must and filter query / 2', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - filter: [ - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + filter: [ + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -338,21 +322,19 @@ test('all but should query / 1', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ], - filter: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ], + filter: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -376,21 +358,19 @@ test('all but should query / 2', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ], - filter: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ], + filter: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -418,19 +398,17 @@ test('all but should query / 3', t => { ) t.deepEqual(query, { - query: { - bool: { - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - filter: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + filter: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -466,25 +444,23 @@ test('all but should query / 4', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 17: '18' } }, - { term: { 19: '20' } }, - { match: { 13: '14' } }, - { term: { 15: '16' } } - ], - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - filter: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 17: '18' } }, + { term: { 19: '20' } }, + { match: { 13: '14' } }, + { term: { 15: '16' } } + ], + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + filter: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } }) @@ -508,23 +484,21 @@ test('filter with should', t => { ) t.deepEqual(query, { - query: { - bool: { - filter: [ - { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - should: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ] - } + bool: { + filter: [ + { + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + should: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ] } - ] - } + } + ] } }) @@ -544,13 +518,11 @@ test('nested with only should', t => { ) t.deepEqual(query, { - query: { - bool: { - should: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ] - } + bool: { + should: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ] } }) @@ -571,18 +543,16 @@ test('nested with only should and minimum_should_match / 1', t => { ) t.deepEqual(query, { - query: { - bool: { - should: [{ - bool: { - should: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - minimum_should_match: 1 - } - }] - } + bool: { + should: [{ + bool: { + should: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + minimum_should_match: 1 + } + }] } }) @@ -602,21 +572,19 @@ test('nested with only should and minimum_should_match / 2', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [{ - bool: { - should: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - minimum_should_match: 1 - } - }], - should: [{ - match: { 5: '6' } - }] - } + bool: { + must: [{ + bool: { + should: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + minimum_should_match: 1 + } + }], + should: [{ + match: { 5: '6' } + }] } }) @@ -640,21 +608,19 @@ test('nested with should and other clause', t => { ) t.deepEqual(query, { - query: { - bool: { - should: [{ - bool: { - should: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - must_not: [ - { match: { 5: '6' } }, - { term: { 7: '8' } } - ] - } - }] - } + bool: { + should: [{ + bool: { + should: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + must_not: [ + { match: { 5: '6' } }, + { term: { 7: '8' } } + ] + } + }] } }) @@ -672,13 +638,11 @@ test('nested with only should', t => { ) t.deepEqual(query, { - query: { - bool: { - should: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ] - } + bool: { + should: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ] } }) @@ -697,14 +661,12 @@ test('nested with only should and minimum_should_match', t => { ) t.deepEqual(query, { - query: { - bool: { - should: [ - { match: { 1: '2' } }, - { term: { 3: '4' } } - ], - minimum_should_match: 1 - } + bool: { + should: [ + { match: { 1: '2' } }, + { term: { 3: '4' } } + ], + minimum_should_match: 1 } }) @@ -729,24 +691,22 @@ test('Should not merge up named queries / 1', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { - bool: { - _name: 'test', - must: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { + bool: { + _name: 'test', + must: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } - ] - } + } + ] } }) @@ -771,24 +731,22 @@ test('Should not merge up named queries / 2', t => { ) t.deepEqual(query, { - query: { - bool: { - must: [ - { match: { 1: '2' } }, - { term: { 3: '4' } }, - { match: { 5: '6' } }, - { term: { 7: '8' } }, - { - bool: { - _name: 'test', - must: [ - { match: { 9: '10' } }, - { term: { 11: '12' } } - ] - } + bool: { + must: [ + { match: { 1: '2' } }, + { term: { 3: '4' } }, + { match: { 5: '6' } }, + { term: { 7: '8' } }, + { + bool: { + _name: 'test', + must: [ + { match: { 9: '10' } }, + { term: { 11: '12' } } + ] } - ] - } + } + ] } }) diff --git a/test/dsl/boolean-and-helpers.test.ts b/test/dsl/boolean-and-helpers.test.ts index e4916726f..bf61d47bf 100644 --- a/test/dsl/boolean-and-helpers.test.ts +++ b/test/dsl/boolean-and-helpers.test.ts @@ -183,13 +183,11 @@ test('AND', t => { const query2 = Q.term('baz', 'faz') t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [ - { match: { foo: 'bar' } }, - { term: { baz: 'faz' } } - ] - } + bool: { + must: [ + { match: { foo: 'bar' } }, + { term: { baz: 'faz' } } + ] } }) @@ -201,11 +199,9 @@ test('AND', t => { const query2 = Q.term('baz', 'faz') t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [{ term: { baz: 'faz' } }], - should: [{ match: { foo: 'bar' } }] - } + bool: { + must: [{ term: { baz: 'faz' } }], + should: [{ match: { foo: 'bar' } }] } }) @@ -217,13 +213,11 @@ test('AND', t => { const query2 = Q.term('baz', 'faz') t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [ - { match: { foo: 'bar' } }, - { term: { baz: 'faz' } } - ] - } + bool: { + must: [ + { match: { foo: 'bar' } }, + { term: { baz: 'faz' } } + ] } }) @@ -235,11 +229,9 @@ test('AND', t => { function noShouldClauses (t, query1, query2) { t.test('No should clauses', t => { t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [{ match: { foo: 'bar' } }], - filter: [{ term: { baz: 'faz' } }] - } + bool: { + must: [{ match: { foo: 'bar' } }], + filter: [{ term: { baz: 'faz' } }] } }) @@ -250,16 +242,14 @@ test('AND', t => { function noShouldClausesWithName (t, query1, query2) { t.test('No should clauses with name', t => { t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [{ - bool: { - must: [{ match: { foo: 'bar' } }], - _name: 'name' - } - }], - filter: [{ term: { baz: 'faz' } }] - } + bool: { + must: [{ + bool: { + must: [{ match: { foo: 'bar' } }], + _name: 'name' + } + }], + filter: [{ term: { baz: 'faz' } }] } }) @@ -272,19 +262,17 @@ test('AND', t => { function shouldClauses (t, query1, query2) { t.test('Should clauses', t => { t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [ - { match: { foo: 'bar' } }, - { - bool: { - should: [ - { term: { baz: 'faz' } } - ] - } + bool: { + must: [ + { match: { foo: 'bar' } }, + { + bool: { + should: [ + { term: { baz: 'faz' } } + ] } - ] - } + } + ] } }) @@ -295,13 +283,11 @@ test('AND', t => { function sameClauseNoShould (t, query1, query2) { t.test('same clauses without should', t => { t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [ - { match: { foo: 'bar' } }, - { term: { baz: 'faz' } } - ] - } + bool: { + must: [ + { match: { foo: 'bar' } }, + { term: { baz: 'faz' } } + ] } }) @@ -312,21 +298,19 @@ test('AND', t => { function sameClauseYesShould (t, query1, query2) { t.test('same clauses with should', t => { t.deepEqual(Q.and(query1, query2), { - query: { - bool: { - must: [ - { - bool: { - should: [ - { term: { baz: 'faz' } } - ] - } + bool: { + must: [ + { + bool: { + should: [ + { term: { baz: 'faz' } } + ] } - ], - should: [ - { match: { foo: 'bar' } } - ] - } + } + ], + should: [ + { match: { foo: 'bar' } } + ] } }) @@ -337,14 +321,12 @@ test('AND', t => { function moreNoShould (t, query1, query2, query3) { t.test('More than two clauses without should', t => { t.deepEqual(Q.and(query1, query2, query3), { - query: { - bool: { - must: [{ match: { foo: 'bar' } }], - filter: [ - { term: { baz: 'faz' } }, - { term: { winter: 'is coming' } } - ] - } + bool: { + must: [{ match: { foo: 'bar' } }], + filter: [ + { term: { baz: 'faz' } }, + { term: { winter: 'is coming' } } + ] } }) @@ -355,20 +337,18 @@ test('AND', t => { function moreYesShould (t, query1, query2, query3) { t.test('More than two clauses with should', t => { t.deepEqual(Q.and(query1, query2, query3), { - query: { - bool: { - must: [ - { match: { foo: 'bar' } }, - { - bool: { - should: [ - { term: { winter: 'is coming' } } - ] - } + bool: { + must: [ + { match: { foo: 'bar' } }, + { + bool: { + should: [ + { term: { winter: 'is coming' } } + ] } - ], - filter: [{ term: { baz: 'faz' } }] - } + } + ], + filter: [{ term: { baz: 'faz' } }] } }) diff --git a/test/dsl/boolean-not-helpers.test.ts b/test/dsl/boolean-not-helpers.test.ts index c53fccf89..8966f239d 100644 --- a/test/dsl/boolean-not-helpers.test.ts +++ b/test/dsl/boolean-not-helpers.test.ts @@ -11,15 +11,13 @@ test('NOT', t => { ) t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ - bool: { - must: [{ match: { foo: 'bar' } }], - filter: [{ term: { baz: 'faz' } }] - } - }] - } + bool: { + must_not: [{ + bool: { + must: [{ match: { foo: 'bar' } }], + filter: [{ term: { baz: 'faz' } }] + } + }] } }) @@ -32,11 +30,9 @@ test('NOT', t => { Q.mustNot(Q.term('baz', 'faz')) ) t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ match: { foo: 'bar' } }], - must: [{ term: { baz: 'faz' } }] - } + bool: { + must_not: [{ match: { foo: 'bar' } }], + must: [{ term: { baz: 'faz' } }] } }) @@ -49,12 +45,10 @@ test('NOT', t => { ) t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ - match: { foo: 'bar' } - }] - } + bool: { + must_not: [{ + match: { foo: 'bar' } + }] } }) @@ -67,12 +61,10 @@ test('NOT', t => { ) t.deepEqual(Q.not(query), { - query: { - bool: { - must: [{ - match: { foo: 'bar' } - }] - } + bool: { + must: [{ + match: { foo: 'bar' } + }] } }) @@ -83,12 +75,10 @@ test('NOT', t => { const query = Q.must(Q.match('foo', 'bar')) t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ - match: { foo: 'bar' } - }] - } + bool: { + must_not: [{ + match: { foo: 'bar' } + }] } }) @@ -99,16 +89,14 @@ test('NOT', t => { const query = Q.should(Q.match('foo', 'bar')) t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ - bool: { - should: [{ - match: { foo: 'bar' } - }] - } - }] - } + bool: { + must_not: [{ + bool: { + should: [{ + match: { foo: 'bar' } + }] + } + }] } }) @@ -119,16 +107,14 @@ test('NOT', t => { const query = Q.filter(Q.match('foo', 'bar')) t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ - bool: { - filter: [{ - match: { foo: 'bar' } - }] - } - }] - } + bool: { + must_not: [{ + bool: { + filter: [{ + match: { foo: 'bar' } + }] + } + }] } }) @@ -139,12 +125,10 @@ test('NOT', t => { const query = Q.mustNot(Q.match('foo', 'bar')) t.deepEqual(Q.not(query), { - query: { - bool: { - must: [{ - match: { foo: 'bar' } - }] - } + bool: { + must: [{ + match: { foo: 'bar' } + }] } }) @@ -155,12 +139,10 @@ test('NOT', t => { const query = Q.match('foo', 'bar') t.deepEqual(Q.not(query), { - query: { - bool: { - must_not: [{ - match: { foo: 'bar' } - }] - } + bool: { + must_not: [{ + match: { foo: 'bar' } + }] } }) diff --git a/test/dsl/boolean-or-helpers.test.ts b/test/dsl/boolean-or-helpers.test.ts index ac78d880a..27fd4df64 100644 --- a/test/dsl/boolean-or-helpers.test.ts +++ b/test/dsl/boolean-or-helpers.test.ts @@ -177,13 +177,11 @@ test('OR', t => { const query2 = Q.term('baz', 'faz') t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { bool: { must: [{ match: { foo: 'bar' } }] } }, - { term: { baz: 'faz' } } - ] - } + bool: { + should: [ + { bool: { must: [{ match: { foo: 'bar' } }] } }, + { term: { baz: 'faz' } } + ] } }) @@ -195,13 +193,11 @@ test('OR', t => { const query2 = Q.term('baz', 'faz') t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { match: { foo: 'bar' } }, - { term: { baz: 'faz' } } - ] - } + bool: { + should: [ + { match: { foo: 'bar' } }, + { term: { baz: 'faz' } } + ] } }) @@ -213,13 +209,11 @@ test('OR', t => { const query2 = Q.term('baz', 'faz') t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { match: { foo: 'bar' } }, - { term: { baz: 'faz' } } - ] - } + bool: { + should: [ + { match: { foo: 'bar' } }, + { term: { baz: 'faz' } } + ] } }) @@ -231,13 +225,11 @@ test('OR', t => { function noShouldClauses (t, query1, query2) { t.test('No should clauses', t => { t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { bool: { must: [{ match: { foo: 'bar' } }] } }, - { bool: { filter: [{ term: { baz: 'faz' } }] } } - ] - } + bool: { + should: [ + { bool: { must: [{ match: { foo: 'bar' } }] } }, + { bool: { filter: [{ term: { baz: 'faz' } }] } } + ] } }) @@ -248,13 +240,11 @@ test('OR', t => { function shouldClauses (t, query1, query2) { t.test('Should clauses', t => { t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { bool: { must: [{ match: { foo: 'bar' } }] } }, - { term: { baz: 'faz' } } - ] - } + bool: { + should: [ + { bool: { must: [{ match: { foo: 'bar' } }] } }, + { term: { baz: 'faz' } } + ] } }) @@ -265,13 +255,11 @@ test('OR', t => { function sameClauseNoShould (t, query1, query2) { t.test('same clauses without should', t => { t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { bool: { must: [{ match: { foo: 'bar' } }] } }, - { bool: { must: [{ term: { baz: 'faz' } }] } } - ] - } + bool: { + should: [ + { bool: { must: [{ match: { foo: 'bar' } }] } }, + { bool: { must: [{ term: { baz: 'faz' } }] } } + ] } }) @@ -282,13 +270,11 @@ test('OR', t => { function sameClauseYesShould (t, query1, query2) { t.test('same clauses with should', t => { t.deepEqual(Q.or(query1, query2), { - query: { - bool: { - should: [ - { match: { foo: 'bar' } }, - { term: { baz: 'faz' } } - ] - } + bool: { + should: [ + { match: { foo: 'bar' } }, + { term: { baz: 'faz' } } + ] } }) @@ -299,14 +285,12 @@ test('OR', t => { function moreNoShould (t, query1, query2, query3) { t.test('More than two clauses without should', t => { t.deepEqual(Q.or(query1, query2, query3), { - query: { - bool: { - should: [ - { bool: { must: [{ match: { foo: 'bar' } }] } }, - { bool: { filter: [{ term: { baz: 'faz' } }] } }, - { bool: { filter: [{ term: { winter: 'is coming' } }] } } - ] - } + bool: { + should: [ + { bool: { must: [{ match: { foo: 'bar' } }] } }, + { bool: { filter: [{ term: { baz: 'faz' } }] } }, + { bool: { filter: [{ term: { winter: 'is coming' } }] } } + ] } }) @@ -317,14 +301,12 @@ test('OR', t => { function moreYesShould (t, query1, query2, query3) { t.test('More than two clauses with should', t => { t.deepEqual(Q.or(query1, query2, query3), { - query: { - bool: { - should: [ - { bool: { must: [{ match: { foo: 'bar' } }] } }, - { bool: { filter: [{ term: { baz: 'faz' } }] } }, - { term: { winter: 'is coming' } } - ] - } + bool: { + should: [ + { bool: { must: [{ match: { foo: 'bar' } }] } }, + { bool: { filter: [{ term: { baz: 'faz' } }] } }, + { term: { winter: 'is coming' } } + ] } }) diff --git a/test/dsl/fluent-query.test.ts b/test/dsl/fluent-query.test.ts index 4a52e10d8..a474f107d 100644 --- a/test/dsl/fluent-query.test.ts +++ b/test/dsl/fluent-query.test.ts @@ -1,85 +1,85 @@ 'use strict' -import { test } from 'tap' -/* eslint-disable no-unused-vars */ -import * as types from '../../dsl/lib/types' -/* eslint-enable no-unused-vars */ -import { F, Q } from '../../dsl' +// import { test } from 'tap' +// /* eslint-disable no-unused-vars */ +// import * as types from '../../dsl/lib/types' +// /* eslint-enable no-unused-vars */ +// import { F, Q } from '../../dsl' -test('match', t => { - t.deepEqual(F() - .match('foo', 'bar') - .match('foo', 'baz') - .build(), - Q( - Q.match('foo', 'bar'), - Q.match('foo', 'baz') - ) - ) +// test('match', t => { +// t.deepEqual(F() +// .match('foo', 'bar') +// .match('foo', 'baz') +// .build(), +// Q( +// Q.match('foo', 'bar'), +// Q.match('foo', 'baz') +// ) +// ) - t.deepEqual(F() - .match('foo', ['bar', 'baz']) - .build(), - Q( - Q.match('foo', ['bar', 'baz']) - ) - ) +// t.deepEqual(F() +// .match('foo', ['bar', 'baz']) +// .build(), +// Q( +// Q.match('foo', ['bar', 'baz']) +// ) +// ) - t.end() -}) +// t.end() +// }) -test('matchPhrase', t => { - t.deepEqual(F() - .matchPhrase('foo', 'bar') - .build(), - Q(Q.matchPhrase('foo', 'bar')) - ) +// test('matchPhrase', t => { +// t.deepEqual(F() +// .matchPhrase('foo', 'bar') +// .build(), +// Q(Q.matchPhrase('foo', 'bar')) +// ) - t.end() -}) +// t.end() +// }) -test('matchPhrasePrefix', t => { - t.deepEqual(F() - .matchPhrasePrefix('foo', 'bar') - .build(), - Q(Q.matchPhrasePrefix('foo', 'bar')) - ) +// test('matchPhrasePrefix', t => { +// t.deepEqual(F() +// .matchPhrasePrefix('foo', 'bar') +// .build(), +// Q(Q.matchPhrasePrefix('foo', 'bar')) +// ) - t.end() -}) +// t.end() +// }) -test('multiMatch', t => { - t.deepEqual(F() - .multiMatch(['foo1', 'foo2'], 'bar') - .build(), - Q(Q.multiMatch(['foo1', 'foo2'], 'bar')) - ) +// test('multiMatch', t => { +// t.deepEqual(F() +// .multiMatch(['foo1', 'foo2'], 'bar') +// .build(), +// Q(Q.multiMatch(['foo1', 'foo2'], 'bar')) +// ) - t.end() -}) +// t.end() +// }) -test('matchAll', t => { - t.deepEqual(F() - .matchAll() - .build(), - Q(Q.matchAll()) - ) +// test('matchAll', t => { +// t.deepEqual(F() +// .matchAll() +// .build(), +// Q(Q.matchAll()) +// ) - t.deepEqual(F() - .matchAll({ boost: 1 }) - .build(), - Q(Q.matchAll({ boost: 1 })) - ) +// t.deepEqual(F() +// .matchAll({ boost: 1 }) +// .build(), +// Q(Q.matchAll({ boost: 1 })) +// ) - t.end() -}) +// t.end() +// }) -test('matchNone', t => { - t.deepEqual(F() - .matchNone() - .build(), - Q(Q.matchNone()) - ) +// test('matchNone', t => { +// t.deepEqual(F() +// .matchNone() +// .build(), +// Q(Q.matchNone()) +// ) - t.end() -}) +// t.end() +// }) diff --git a/test/dsl/query.test.ts b/test/dsl/query.test.ts index 58c7a3e6a..7e28487f8 100644 --- a/test/dsl/query.test.ts +++ b/test/dsl/query.test.ts @@ -9,13 +9,13 @@ import { Q } from '../../dsl' test('Q is a function that creates the final query object', t => { t.type(Q, 'function') - t.deepEqual(Q({ a: 1 }, { b: 2 }, { c: 3 }), { + t.deepEqual(Q(c('a'), c('b'), c('c')), { query: { bool: { must: [ - { a: 1 }, - { b: 2 }, - { c: 3 } + c('a'), + c('b'), + c('c') ] } } @@ -66,9 +66,9 @@ test('Q is a function that creates the final query object', t => { [randomTopLevelKey]: 42 }) - t.deepEqual(Q({ query: { function_score: { foo: 'bar' } } }, { [randomTopLevelKey]: 42 }), { + t.deepEqual(Q({ query: { function_score: { max_boost: 42 } } }, { [randomTopLevelKey]: 42 }), { query: { - function_score: { foo: 'bar' } + function_score: { max_boost: 42 } }, [randomTopLevelKey]: 42 }) @@ -88,9 +88,9 @@ test('Compile a query (safe)', t => { t.type(Q.compile, 'function') const query = Q( - { a: Q.param('a') }, - { b: Q.param('b') }, - { c: Q.param('c') } + Q.match('a', Q.param('a')), + Q.match('b', Q.param('b')), + Q.match('c', Q.param('c')) ) interface Input { @@ -104,9 +104,9 @@ test('Compile a query (safe)', t => { query: { bool: { must: [ - { a: 1 }, - { b: 2 }, - { c: 3 } + { match: { a: 1 } }, + { match: { b: 2 } }, + { match: { c: 3 } } ] } } @@ -126,9 +126,9 @@ test('Compile a query (unsafe)', t => { t.type(Q.compile, 'function') const query = Q( - { a: Q.param('a') }, - { b: Q.param('b') }, - { c: Q.param('c') } + Q.match('a', Q.param('a')), + Q.match('b', Q.param('b')), + Q.match('c', Q.param('c')) ) interface Input { @@ -142,9 +142,9 @@ test('Compile a query (unsafe)', t => { query: { bool: { must: [ - { a: 1 }, - { b: 2 }, - { c: 3 } + { match: { a: 1 } }, + { match: { b: 2 } }, + { match: { c: 3 } } ] } } @@ -170,11 +170,11 @@ test('match returns a match query', t => { }) t.test('complex query', t => { - t.deepEqual(Q.match('foo', 'bar', { operator: 'and' }), { + t.deepEqual(Q.match('foo', 'bar', { analyzer: 'and' }), { match: { foo: { query: 'bar', - operator: 'and' + analyzer: 'and' } } }) @@ -237,11 +237,11 @@ test('matchPhrasePrefix returns a match_phrase_prefix query', t => { test('multiMatch returns a multi_match query', t => { t.type(Q.multiMatch, 'function') - t.deepEqual(Q.multiMatch(['foo', 'baz'], 'bar', { type: 'best_fields' }), { + t.deepEqual(Q.multiMatch(['foo', 'baz'], 'bar', { analyzer: 'best_fields' }), { multi_match: { query: 'bar', fields: ['foo', 'baz'], - type: 'best_fields' + analyzer: 'best_fields' } }) @@ -251,8 +251,8 @@ test('multiMatch returns a multi_match query', t => { test('matchAll returns a match_all query', t => { t.type(Q.matchAll, 'function') - t.deepEqual(Q.matchAll({ boost: 1.2 }), { - match_all: { boost: 1.2 } + t.deepEqual(Q.matchAll({ norm_field: 'foobar' }), { + match_all: { norm_field: 'foobar' } }) t.end() @@ -299,10 +299,10 @@ test('queryString returns a query_string query', t => { test('simpleQueryString returns a simple_query_string query', t => { t.type(Q.simpleQueryString, 'function') - t.deepEqual(Q.simpleQueryString('foo', { default_field: 'content' }), { + t.deepEqual(Q.simpleQueryString('foo', { analyzer: 'content' }), { simple_query_string: { query: 'foo', - default_field: 'content' + analyzer: 'content' } }) @@ -756,26 +756,22 @@ test('bool returns a bool query block', t => { t.type(Q.bool, 'function') t.deepEqual(Q.bool(Q.must(c('foo')), Q.should(c('bar')), Q.filter(c('baz'))), { - query: { - bool: { - must: [c('foo')], - should: [c('bar')], - filter: [c('baz')] - } + bool: { + must: [c('foo')], + should: [c('bar')], + filter: [c('baz')] } }) - t.deepEqual(Q.bool(), { query: { bool: {} } }) - t.deepEqual(Q.bool(undefined), { query: { bool: {} } }) + t.deepEqual(Q.bool(), { bool: {} }) + t.deepEqual(Q.bool(undefined), { bool: {} }) t.deepEqual(Q.bool(Q.must(c('foo')), Q.should(c('bar')), Q.mustNot(c('foz')), Q.filter(c('baz'), c('faz'))), { - query: { - bool: { - must: [c('foo')], - must_not: [c('foz')], - should: [c('bar')], - filter: [c('baz'), c('faz')] - } + bool: { + must: [c('foo')], + must_not: [c('foz')], + should: [c('bar')], + filter: [c('baz'), c('faz')] } }) @@ -788,15 +784,13 @@ test('bool returns a bool query block', t => { Q.should(c('bar')), Q.filter(c('baz')) ), { - query: { - bool: { - must: [ - c('foo'), - { bool: { must: [c('faz')], _name: 'name' } } - ], - should: [c('bar')], - filter: [c('baz')] - } + bool: { + must: [ + c('foo'), + { bool: { must: [c('faz')], _name: 'name' } } + ], + should: [c('bar')], + filter: [c('baz')] } }) @@ -806,17 +800,15 @@ test('bool returns a bool query block', t => { Q.match('baz', 'faz'), Q.minShouldMatch(1) ), { - query: { - bool: { - must: [ - { term: { hello: 'world' } } - ], - should: [ - { match: { foo: 'bar' } }, - { match: { baz: 'faz' } } - ], - minimum_should_match: 1 - } + bool: { + must: [ + { term: { hello: 'world' } } + ], + should: [ + { match: { foo: 'bar' } }, + { match: { baz: 'faz' } } + ], + minimum_should_match: 1 } }) @@ -826,14 +818,12 @@ test('bool returns a bool query block', t => { Q.match('baz', 'faz'), Q.minShouldMatch(2) ), { - query: { - bool: { - must: [ - { term: { hello: 'world' } }, - { match: { foo: 'bar' } }, - { match: { baz: 'faz' } } - ] - } + bool: { + must: [ + { term: { hello: 'world' } }, + { match: { foo: 'bar' } }, + { match: { baz: 'faz' } } + ] } }) @@ -842,13 +832,11 @@ test('bool returns a bool query block', t => { Q.match('baz', 'faz'), Q.minShouldMatch(2) ), { - query: { - bool: { - must: [ - { match: { foo: 'bar' } }, - { match: { baz: 'faz' } } - ] - } + bool: { + must: [ + { match: { foo: 'bar' } }, + { match: { baz: 'faz' } } + ] } }) @@ -892,10 +880,10 @@ test('disMax returns a dis_max query block', t => { t.type(Q.disMax, 'function') t.test('simple query', t => { - t.deepEqual(Q.disMax([{ a: 1 }, { b: 2 }, { c: 3 }]), { + t.deepEqual(Q.disMax([c('a'), c('b'), c('c')]), { query: { dis_max: { - queries: [{ a: 1 }, { b: 2 }, { c: 3 }] + queries: [c('a'), c('b'), c('c')] } } }) @@ -903,12 +891,12 @@ test('disMax returns a dis_max query block', t => { }) t.test('complex query', t => { - t.deepEqual(Q.disMax([{ a: 1 }, { b: 2 }, { c: 3 }], { tie_breaker: 1.0, boost: 1.0 }), { + t.deepEqual(Q.disMax([c('a'), c('b'), c('c')], { tie_breaker: 1.0, boost: 1.0 }), { query: { dis_max: { tie_breaker: 1.0, boost: 1.0, - queries: [{ a: 1 }, { b: 2 }, { c: 3 }] + queries: [c('a'), c('b'), c('c')] } } }) @@ -987,5 +975,5 @@ test('name', t => { // build a condition bloc function c (key: string): types.Condition { - return { [key]: key } + return { match: { [key]: key } } }