Updated test

This commit is contained in:
delvedor
2020-09-07 17:45:26 +02:00
parent 48178df02e
commit 126199a5ea
6 changed files with 547 additions and 657 deletions

View File

@ -20,17 +20,15 @@ test('must only query', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -60,21 +58,19 @@ test('must and must_not query', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ],
], must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 13: '14' } },
{ match: { 13: '14' } }, { term: { 15: '16' } }
{ term: { 15: '16' } } ]
]
}
} }
}) })
@ -106,21 +102,19 @@ test('must and must_not query (mixed and nested)', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } },
{ term: { 11: '12' } }, { term: { 15: '16' } }
{ term: { 15: '16' } } ],
], must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 13: '14' } }
{ match: { 13: '14' } } ]
]
}
} }
}) })
@ -140,17 +134,15 @@ test('must and should query', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], should: [
should: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ]
]
}
} }
}) })
@ -178,25 +170,23 @@ test('must and should query (nested) / 1', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, {
{ bool: {
bool: { must: [
must: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ],
], should: [
should: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
] }
} ]
} }
}) })
@ -222,25 +212,23 @@ test('must and should query (nested) / 2', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, {
{ bool: {
bool: { must: [
must: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ],
], should: [
should: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
] }
} ]
} }
}) })
@ -266,19 +254,17 @@ test('must and filter query / 1', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], filter: [
filter: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -302,19 +288,17 @@ test('must and filter query / 2', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], filter: [
filter: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -338,21 +322,19 @@ test('all but should query / 1', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ],
], filter: [
filter: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -376,21 +358,19 @@ test('all but should query / 2', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ],
], filter: [
filter: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -418,19 +398,17 @@ test('all but should query / 3', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], filter: [
filter: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -466,25 +444,23 @@ test('all but should query / 4', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 17: '18' } },
{ match: { 17: '18' } }, { term: { 19: '20' } },
{ term: { 19: '20' } }, { match: { 13: '14' } },
{ match: { 13: '14' } }, { term: { 15: '16' } }
{ term: { 15: '16' } } ],
], must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], filter: [
filter: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
}) })
@ -508,23 +484,21 @@ test('filter with should', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { filter: [
filter: [ {
{ bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], should: [
should: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ]
]
}
} }
] }
} ]
} }
}) })
@ -544,13 +518,11 @@ test('nested with only should', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { should: [
should: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ]
]
}
} }
}) })
@ -571,18 +543,16 @@ test('nested with only should and minimum_should_match / 1', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { should: [{
should: [{ bool: {
bool: { should: [
should: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], minimum_should_match: 1
minimum_should_match: 1 }
} }]
}]
}
} }
}) })
@ -602,21 +572,19 @@ test('nested with only should and minimum_should_match / 2', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [{
must: [{ bool: {
bool: { should: [
should: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], minimum_should_match: 1
minimum_should_match: 1 }
} }],
}], should: [{
should: [{ match: { 5: '6' }
match: { 5: '6' } }]
}]
}
} }
}) })
@ -640,21 +608,19 @@ test('nested with should and other clause', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { should: [{
should: [{ bool: {
bool: { should: [
should: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], must_not: [
must_not: [ { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } }
{ term: { 7: '8' } } ]
] }
} }]
}]
}
} }
}) })
@ -672,13 +638,11 @@ test('nested with only should', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { should: [
should: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ]
]
}
} }
}) })
@ -697,14 +661,12 @@ test('nested with only should and minimum_should_match', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { should: [
should: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } }
{ term: { 3: '4' } } ],
], minimum_should_match: 1
minimum_should_match: 1
}
} }
}) })
@ -729,24 +691,22 @@ test('Should not merge up named queries / 1', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, {
{ bool: {
bool: { _name: 'test',
_name: 'test', must: [
must: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
] }
} ]
} }
}) })
@ -771,24 +731,22 @@ test('Should not merge up named queries / 2', t => {
) )
t.deepEqual(query, { t.deepEqual(query, {
query: { bool: {
bool: { must: [
must: [ { match: { 1: '2' } },
{ match: { 1: '2' } }, { term: { 3: '4' } },
{ term: { 3: '4' } }, { match: { 5: '6' } },
{ match: { 5: '6' } }, { term: { 7: '8' } },
{ term: { 7: '8' } }, {
{ bool: {
bool: { _name: 'test',
_name: 'test', must: [
must: [ { match: { 9: '10' } },
{ match: { 9: '10' } }, { term: { 11: '12' } }
{ term: { 11: '12' } } ]
]
}
} }
] }
} ]
} }
}) })

View File

@ -183,13 +183,11 @@ test('AND', t => {
const query2 = Q.term('baz', 'faz') const query2 = Q.term('baz', 'faz')
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [
must: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -201,11 +199,9 @@ test('AND', t => {
const query2 = Q.term('baz', 'faz') const query2 = Q.term('baz', 'faz')
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [{ term: { baz: 'faz' } }],
must: [{ term: { baz: 'faz' } }], should: [{ match: { foo: 'bar' } }]
should: [{ match: { foo: 'bar' } }]
}
} }
}) })
@ -217,13 +213,11 @@ test('AND', t => {
const query2 = Q.term('baz', 'faz') const query2 = Q.term('baz', 'faz')
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [
must: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -235,11 +229,9 @@ test('AND', t => {
function noShouldClauses (t, query1, query2) { function noShouldClauses (t, query1, query2) {
t.test('No should clauses', t => { t.test('No should clauses', t => {
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [{ match: { foo: 'bar' } }],
must: [{ match: { foo: 'bar' } }], filter: [{ term: { baz: 'faz' } }]
filter: [{ term: { baz: 'faz' } }]
}
} }
}) })
@ -250,16 +242,14 @@ test('AND', t => {
function noShouldClausesWithName (t, query1, query2) { function noShouldClausesWithName (t, query1, query2) {
t.test('No should clauses with name', t => { t.test('No should clauses with name', t => {
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [{
must: [{ bool: {
bool: { must: [{ match: { foo: 'bar' } }],
must: [{ match: { foo: 'bar' } }], _name: 'name'
_name: 'name' }
} }],
}], filter: [{ term: { baz: 'faz' } }]
filter: [{ term: { baz: 'faz' } }]
}
} }
}) })
@ -272,19 +262,17 @@ test('AND', t => {
function shouldClauses (t, query1, query2) { function shouldClauses (t, query1, query2) {
t.test('Should clauses', t => { t.test('Should clauses', t => {
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [
must: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, {
{ bool: {
bool: { should: [
should: [ { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
] }
} ]
} }
}) })
@ -295,13 +283,11 @@ test('AND', t => {
function sameClauseNoShould (t, query1, query2) { function sameClauseNoShould (t, query1, query2) {
t.test('same clauses without should', t => { t.test('same clauses without should', t => {
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [
must: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -312,21 +298,19 @@ test('AND', t => {
function sameClauseYesShould (t, query1, query2) { function sameClauseYesShould (t, query1, query2) {
t.test('same clauses with should', t => { t.test('same clauses with should', t => {
t.deepEqual(Q.and(query1, query2), { t.deepEqual(Q.and(query1, query2), {
query: { bool: {
bool: { must: [
must: [ {
{ bool: {
bool: { should: [
should: [ { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
], }
should: [ ],
{ match: { foo: 'bar' } } should: [
] { match: { foo: 'bar' } }
} ]
} }
}) })
@ -337,14 +321,12 @@ test('AND', t => {
function moreNoShould (t, query1, query2, query3) { function moreNoShould (t, query1, query2, query3) {
t.test('More than two clauses without should', t => { t.test('More than two clauses without should', t => {
t.deepEqual(Q.and(query1, query2, query3), { t.deepEqual(Q.and(query1, query2, query3), {
query: { bool: {
bool: { must: [{ match: { foo: 'bar' } }],
must: [{ match: { foo: 'bar' } }], filter: [
filter: [ { term: { baz: 'faz' } },
{ term: { baz: 'faz' } }, { term: { winter: 'is coming' } }
{ term: { winter: 'is coming' } } ]
]
}
} }
}) })
@ -355,20 +337,18 @@ test('AND', t => {
function moreYesShould (t, query1, query2, query3) { function moreYesShould (t, query1, query2, query3) {
t.test('More than two clauses with should', t => { t.test('More than two clauses with should', t => {
t.deepEqual(Q.and(query1, query2, query3), { t.deepEqual(Q.and(query1, query2, query3), {
query: { bool: {
bool: { must: [
must: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, {
{ bool: {
bool: { should: [
should: [ { term: { winter: 'is coming' } }
{ term: { winter: 'is coming' } } ]
]
}
} }
], }
filter: [{ term: { baz: 'faz' } }] ],
} filter: [{ term: { baz: 'faz' } }]
} }
}) })

View File

@ -11,15 +11,13 @@ test('NOT', t => {
) )
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{
must_not: [{ bool: {
bool: { must: [{ match: { foo: 'bar' } }],
must: [{ match: { foo: 'bar' } }], filter: [{ term: { baz: 'faz' } }]
filter: [{ term: { baz: 'faz' } }] }
} }]
}]
}
} }
}) })
@ -32,11 +30,9 @@ test('NOT', t => {
Q.mustNot(Q.term('baz', 'faz')) Q.mustNot(Q.term('baz', 'faz'))
) )
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{ match: { foo: 'bar' } }],
must_not: [{ match: { foo: 'bar' } }], must: [{ term: { baz: 'faz' } }]
must: [{ term: { baz: 'faz' } }]
}
} }
}) })
@ -49,12 +45,10 @@ test('NOT', t => {
) )
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{
must_not: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}]
}
} }
}) })
@ -67,12 +61,10 @@ test('NOT', t => {
) )
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must: [{
must: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}]
}
} }
}) })
@ -83,12 +75,10 @@ test('NOT', t => {
const query = Q.must(Q.match('foo', 'bar')) const query = Q.must(Q.match('foo', 'bar'))
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{
must_not: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}]
}
} }
}) })
@ -99,16 +89,14 @@ test('NOT', t => {
const query = Q.should(Q.match('foo', 'bar')) const query = Q.should(Q.match('foo', 'bar'))
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{
must_not: [{ bool: {
bool: { should: [{
should: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}] }
} }]
}]
}
} }
}) })
@ -119,16 +107,14 @@ test('NOT', t => {
const query = Q.filter(Q.match('foo', 'bar')) const query = Q.filter(Q.match('foo', 'bar'))
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{
must_not: [{ bool: {
bool: { filter: [{
filter: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}] }
} }]
}]
}
} }
}) })
@ -139,12 +125,10 @@ test('NOT', t => {
const query = Q.mustNot(Q.match('foo', 'bar')) const query = Q.mustNot(Q.match('foo', 'bar'))
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must: [{
must: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}]
}
} }
}) })
@ -155,12 +139,10 @@ test('NOT', t => {
const query = Q.match('foo', 'bar') const query = Q.match('foo', 'bar')
t.deepEqual(Q.not(query), { t.deepEqual(Q.not(query), {
query: { bool: {
bool: { must_not: [{
must_not: [{ match: { foo: 'bar' }
match: { foo: 'bar' } }]
}]
}
} }
}) })

View File

@ -177,13 +177,11 @@ test('OR', t => {
const query2 = Q.term('baz', 'faz') const query2 = Q.term('baz', 'faz')
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { bool: { must: [{ match: { foo: 'bar' } }] } },
{ bool: { must: [{ match: { foo: 'bar' } }] } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -195,13 +193,11 @@ test('OR', t => {
const query2 = Q.term('baz', 'faz') const query2 = Q.term('baz', 'faz')
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -213,13 +209,11 @@ test('OR', t => {
const query2 = Q.term('baz', 'faz') const query2 = Q.term('baz', 'faz')
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -231,13 +225,11 @@ test('OR', t => {
function noShouldClauses (t, query1, query2) { function noShouldClauses (t, query1, query2) {
t.test('No should clauses', t => { t.test('No should clauses', t => {
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { bool: { must: [{ match: { foo: 'bar' } }] } },
{ bool: { must: [{ match: { foo: 'bar' } }] } }, { bool: { filter: [{ term: { baz: 'faz' } }] } }
{ bool: { filter: [{ term: { baz: 'faz' } }] } } ]
]
}
} }
}) })
@ -248,13 +240,11 @@ test('OR', t => {
function shouldClauses (t, query1, query2) { function shouldClauses (t, query1, query2) {
t.test('Should clauses', t => { t.test('Should clauses', t => {
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { bool: { must: [{ match: { foo: 'bar' } }] } },
{ bool: { must: [{ match: { foo: 'bar' } }] } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -265,13 +255,11 @@ test('OR', t => {
function sameClauseNoShould (t, query1, query2) { function sameClauseNoShould (t, query1, query2) {
t.test('same clauses without should', t => { t.test('same clauses without should', t => {
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { bool: { must: [{ match: { foo: 'bar' } }] } },
{ bool: { must: [{ match: { foo: 'bar' } }] } }, { bool: { must: [{ term: { baz: 'faz' } }] } }
{ bool: { must: [{ term: { baz: 'faz' } }] } } ]
]
}
} }
}) })
@ -282,13 +270,11 @@ test('OR', t => {
function sameClauseYesShould (t, query1, query2) { function sameClauseYesShould (t, query1, query2) {
t.test('same clauses with should', t => { t.test('same clauses with should', t => {
t.deepEqual(Q.or(query1, query2), { t.deepEqual(Q.or(query1, query2), {
query: { bool: {
bool: { should: [
should: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { term: { baz: 'faz' } }
{ term: { baz: 'faz' } } ]
]
}
} }
}) })
@ -299,14 +285,12 @@ test('OR', t => {
function moreNoShould (t, query1, query2, query3) { function moreNoShould (t, query1, query2, query3) {
t.test('More than two clauses without should', t => { t.test('More than two clauses without should', t => {
t.deepEqual(Q.or(query1, query2, query3), { t.deepEqual(Q.or(query1, query2, query3), {
query: { bool: {
bool: { should: [
should: [ { bool: { must: [{ match: { foo: 'bar' } }] } },
{ bool: { must: [{ match: { foo: 'bar' } }] } }, { bool: { filter: [{ term: { baz: 'faz' } }] } },
{ bool: { filter: [{ term: { baz: 'faz' } }] } }, { bool: { filter: [{ term: { winter: 'is coming' } }] } }
{ bool: { filter: [{ term: { winter: 'is coming' } }] } } ]
]
}
} }
}) })
@ -317,14 +301,12 @@ test('OR', t => {
function moreYesShould (t, query1, query2, query3) { function moreYesShould (t, query1, query2, query3) {
t.test('More than two clauses with should', t => { t.test('More than two clauses with should', t => {
t.deepEqual(Q.or(query1, query2, query3), { t.deepEqual(Q.or(query1, query2, query3), {
query: { bool: {
bool: { should: [
should: [ { bool: { must: [{ match: { foo: 'bar' } }] } },
{ bool: { must: [{ match: { foo: 'bar' } }] } }, { bool: { filter: [{ term: { baz: 'faz' } }] } },
{ bool: { filter: [{ term: { baz: 'faz' } }] } }, { term: { winter: 'is coming' } }
{ term: { winter: 'is coming' } } ]
]
}
} }
}) })

View File

@ -1,85 +1,85 @@
'use strict' 'use strict'
import { test } from 'tap' // import { test } from 'tap'
/* eslint-disable no-unused-vars */ // /* eslint-disable no-unused-vars */
import * as types from '../../dsl/lib/types' // import * as types from '../../dsl/lib/types'
/* eslint-enable no-unused-vars */ // /* eslint-enable no-unused-vars */
import { F, Q } from '../../dsl' // import { F, Q } from '../../dsl'
test('match', t => { // test('match', t => {
t.deepEqual(F() // t.deepEqual(F()
.match('foo', 'bar') // .match('foo', 'bar')
.match('foo', 'baz') // .match('foo', 'baz')
.build(), // .build(),
Q( // Q(
Q.match('foo', 'bar'), // Q.match('foo', 'bar'),
Q.match('foo', 'baz') // Q.match('foo', 'baz')
) // )
) // )
t.deepEqual(F() // t.deepEqual(F()
.match('foo', ['bar', 'baz']) // .match('foo', ['bar', 'baz'])
.build(), // .build(),
Q( // Q(
Q.match('foo', ['bar', 'baz']) // Q.match('foo', ['bar', 'baz'])
) // )
) // )
t.end() // t.end()
}) // })
test('matchPhrase', t => { // test('matchPhrase', t => {
t.deepEqual(F() // t.deepEqual(F()
.matchPhrase('foo', 'bar') // .matchPhrase('foo', 'bar')
.build(), // .build(),
Q(Q.matchPhrase('foo', 'bar')) // Q(Q.matchPhrase('foo', 'bar'))
) // )
t.end() // t.end()
}) // })
test('matchPhrasePrefix', t => { // test('matchPhrasePrefix', t => {
t.deepEqual(F() // t.deepEqual(F()
.matchPhrasePrefix('foo', 'bar') // .matchPhrasePrefix('foo', 'bar')
.build(), // .build(),
Q(Q.matchPhrasePrefix('foo', 'bar')) // Q(Q.matchPhrasePrefix('foo', 'bar'))
) // )
t.end() // t.end()
}) // })
test('multiMatch', t => { // test('multiMatch', t => {
t.deepEqual(F() // t.deepEqual(F()
.multiMatch(['foo1', 'foo2'], 'bar') // .multiMatch(['foo1', 'foo2'], 'bar')
.build(), // .build(),
Q(Q.multiMatch(['foo1', 'foo2'], 'bar')) // Q(Q.multiMatch(['foo1', 'foo2'], 'bar'))
) // )
t.end() // t.end()
}) // })
test('matchAll', t => { // test('matchAll', t => {
t.deepEqual(F() // t.deepEqual(F()
.matchAll() // .matchAll()
.build(), // .build(),
Q(Q.matchAll()) // Q(Q.matchAll())
) // )
t.deepEqual(F() // t.deepEqual(F()
.matchAll({ boost: 1 }) // .matchAll({ boost: 1 })
.build(), // .build(),
Q(Q.matchAll({ boost: 1 })) // Q(Q.matchAll({ boost: 1 }))
) // )
t.end() // t.end()
}) // })
test('matchNone', t => { // test('matchNone', t => {
t.deepEqual(F() // t.deepEqual(F()
.matchNone() // .matchNone()
.build(), // .build(),
Q(Q.matchNone()) // Q(Q.matchNone())
) // )
t.end() // t.end()
}) // })

View File

@ -9,13 +9,13 @@ import { Q } from '../../dsl'
test('Q is a function that creates the final query object', t => { test('Q is a function that creates the final query object', t => {
t.type(Q, 'function') t.type(Q, 'function')
t.deepEqual(Q({ a: 1 }, { b: 2 }, { c: 3 }), { t.deepEqual(Q(c('a'), c('b'), c('c')), {
query: { query: {
bool: { bool: {
must: [ must: [
{ a: 1 }, c('a'),
{ b: 2 }, c('b'),
{ c: 3 } c('c')
] ]
} }
} }
@ -66,9 +66,9 @@ test('Q is a function that creates the final query object', t => {
[randomTopLevelKey]: 42 [randomTopLevelKey]: 42
}) })
t.deepEqual(Q({ query: { function_score: { foo: 'bar' } } }, { [randomTopLevelKey]: 42 }), { t.deepEqual(Q({ query: { function_score: { max_boost: 42 } } }, { [randomTopLevelKey]: 42 }), {
query: { query: {
function_score: { foo: 'bar' } function_score: { max_boost: 42 }
}, },
[randomTopLevelKey]: 42 [randomTopLevelKey]: 42
}) })
@ -88,9 +88,9 @@ test('Compile a query (safe)', t => {
t.type(Q.compile, 'function') t.type(Q.compile, 'function')
const query = Q( const query = Q(
{ a: Q.param('a') }, Q.match('a', Q.param('a')),
{ b: Q.param('b') }, Q.match('b', Q.param('b')),
{ c: Q.param('c') } Q.match('c', Q.param('c'))
) )
interface Input { interface Input {
@ -104,9 +104,9 @@ test('Compile a query (safe)', t => {
query: { query: {
bool: { bool: {
must: [ must: [
{ a: 1 }, { match: { a: 1 } },
{ b: 2 }, { match: { b: 2 } },
{ c: 3 } { match: { c: 3 } }
] ]
} }
} }
@ -126,9 +126,9 @@ test('Compile a query (unsafe)', t => {
t.type(Q.compile, 'function') t.type(Q.compile, 'function')
const query = Q( const query = Q(
{ a: Q.param('a') }, Q.match('a', Q.param('a')),
{ b: Q.param('b') }, Q.match('b', Q.param('b')),
{ c: Q.param('c') } Q.match('c', Q.param('c'))
) )
interface Input { interface Input {
@ -142,9 +142,9 @@ test('Compile a query (unsafe)', t => {
query: { query: {
bool: { bool: {
must: [ must: [
{ a: 1 }, { match: { a: 1 } },
{ b: 2 }, { match: { b: 2 } },
{ c: 3 } { match: { c: 3 } }
] ]
} }
} }
@ -170,11 +170,11 @@ test('match returns a match query', t => {
}) })
t.test('complex query', t => { t.test('complex query', t => {
t.deepEqual(Q.match('foo', 'bar', { operator: 'and' }), { t.deepEqual(Q.match('foo', 'bar', { analyzer: 'and' }), {
match: { match: {
foo: { foo: {
query: 'bar', 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 => { test('multiMatch returns a multi_match query', t => {
t.type(Q.multiMatch, 'function') 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: { multi_match: {
query: 'bar', query: 'bar',
fields: ['foo', 'baz'], 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 => { test('matchAll returns a match_all query', t => {
t.type(Q.matchAll, 'function') t.type(Q.matchAll, 'function')
t.deepEqual(Q.matchAll({ boost: 1.2 }), { t.deepEqual(Q.matchAll({ norm_field: 'foobar' }), {
match_all: { boost: 1.2 } match_all: { norm_field: 'foobar' }
}) })
t.end() t.end()
@ -299,10 +299,10 @@ test('queryString returns a query_string query', t => {
test('simpleQueryString returns a simple_query_string query', t => { test('simpleQueryString returns a simple_query_string query', t => {
t.type(Q.simpleQueryString, 'function') t.type(Q.simpleQueryString, 'function')
t.deepEqual(Q.simpleQueryString('foo', { default_field: 'content' }), { t.deepEqual(Q.simpleQueryString('foo', { analyzer: 'content' }), {
simple_query_string: { simple_query_string: {
query: 'foo', 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.type(Q.bool, 'function')
t.deepEqual(Q.bool(Q.must(c('foo')), Q.should(c('bar')), Q.filter(c('baz'))), { t.deepEqual(Q.bool(Q.must(c('foo')), Q.should(c('bar')), Q.filter(c('baz'))), {
query: { bool: {
bool: { must: [c('foo')],
must: [c('foo')], should: [c('bar')],
should: [c('bar')], filter: [c('baz')]
filter: [c('baz')]
}
} }
}) })
t.deepEqual(Q.bool(), { query: { bool: {} } }) t.deepEqual(Q.bool(), { bool: {} })
t.deepEqual(Q.bool(undefined), { query: { 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'))), { t.deepEqual(Q.bool(Q.must(c('foo')), Q.should(c('bar')), Q.mustNot(c('foz')), Q.filter(c('baz'), c('faz'))), {
query: { bool: {
bool: { must: [c('foo')],
must: [c('foo')], must_not: [c('foz')],
must_not: [c('foz')], should: [c('bar')],
should: [c('bar')], filter: [c('baz'), c('faz')]
filter: [c('baz'), c('faz')]
}
} }
}) })
@ -788,15 +784,13 @@ test('bool returns a bool query block', t => {
Q.should(c('bar')), Q.should(c('bar')),
Q.filter(c('baz')) Q.filter(c('baz'))
), { ), {
query: { bool: {
bool: { must: [
must: [ c('foo'),
c('foo'), { bool: { must: [c('faz')], _name: 'name' } }
{ bool: { must: [c('faz')], _name: 'name' } } ],
], should: [c('bar')],
should: [c('bar')], filter: [c('baz')]
filter: [c('baz')]
}
} }
}) })
@ -806,17 +800,15 @@ test('bool returns a bool query block', t => {
Q.match('baz', 'faz'), Q.match('baz', 'faz'),
Q.minShouldMatch(1) Q.minShouldMatch(1)
), { ), {
query: { bool: {
bool: { must: [
must: [ { term: { hello: 'world' } }
{ term: { hello: 'world' } } ],
], should: [
should: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { match: { baz: 'faz' } }
{ match: { baz: 'faz' } } ],
], minimum_should_match: 1
minimum_should_match: 1
}
} }
}) })
@ -826,14 +818,12 @@ test('bool returns a bool query block', t => {
Q.match('baz', 'faz'), Q.match('baz', 'faz'),
Q.minShouldMatch(2) Q.minShouldMatch(2)
), { ), {
query: { bool: {
bool: { must: [
must: [ { term: { hello: 'world' } },
{ term: { hello: 'world' } }, { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { match: { baz: 'faz' } }
{ match: { baz: 'faz' } } ]
]
}
} }
}) })
@ -842,13 +832,11 @@ test('bool returns a bool query block', t => {
Q.match('baz', 'faz'), Q.match('baz', 'faz'),
Q.minShouldMatch(2) Q.minShouldMatch(2)
), { ), {
query: { bool: {
bool: { must: [
must: [ { match: { foo: 'bar' } },
{ match: { foo: 'bar' } }, { match: { baz: 'faz' } }
{ match: { baz: 'faz' } } ]
]
}
} }
}) })
@ -892,10 +880,10 @@ test('disMax returns a dis_max query block', t => {
t.type(Q.disMax, 'function') t.type(Q.disMax, 'function')
t.test('simple query', t => { 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: { query: {
dis_max: { 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.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: { query: {
dis_max: { dis_max: {
tie_breaker: 1.0, tie_breaker: 1.0,
boost: 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 // build a condition bloc
function c (key: string): types.Condition { function c (key: string): types.Condition {
return { [key]: key } return { match: { [key]: key } }
} }