-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ua/es_client_fix
- Loading branch information
Showing
69 changed files
with
2,190 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
280 changes: 280 additions & 0 deletions
280
src/plugins/data/common/es_query/kuery/node_types/node_builder.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { nodeBuilder } from './node_builder'; | ||
import { toElasticsearchQuery } from '../index'; | ||
|
||
describe('nodeBuilder', () => { | ||
describe('is method', () => { | ||
test('string value', () => { | ||
const nodes = nodeBuilder.is('foo', 'bar'); | ||
const query = toElasticsearchQuery(nodes); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo": "bar", | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('KueryNode value', () => { | ||
const literalValue = { | ||
type: 'literal' as 'literal', | ||
value: 'bar', | ||
}; | ||
const nodes = nodeBuilder.is('foo', literalValue); | ||
const query = toElasticsearchQuery(nodes); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo": "bar", | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
describe('and method', () => { | ||
test('single clause', () => { | ||
const nodes = [nodeBuilder.is('foo', 'bar')]; | ||
const query = toElasticsearchQuery(nodeBuilder.and(nodes)); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo": "bar", | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('two clauses', () => { | ||
const nodes = [nodeBuilder.is('foo1', 'bar1'), nodeBuilder.is('foo2', 'bar2')]; | ||
const query = toElasticsearchQuery(nodeBuilder.and(nodes)); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"filter": Array [ | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo1": "bar1", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo2": "bar2", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('three clauses', () => { | ||
const nodes = [ | ||
nodeBuilder.is('foo1', 'bar1'), | ||
nodeBuilder.is('foo2', 'bar2'), | ||
nodeBuilder.is('foo3', 'bar3'), | ||
]; | ||
const query = toElasticsearchQuery(nodeBuilder.and(nodes)); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"filter": Array [ | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo1": "bar1", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo2": "bar2", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo3": "bar3", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
describe('or method', () => { | ||
test('single clause', () => { | ||
const nodes = [nodeBuilder.is('foo', 'bar')]; | ||
const query = toElasticsearchQuery(nodeBuilder.or(nodes)); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo": "bar", | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('two clauses', () => { | ||
const nodes = [nodeBuilder.is('foo1', 'bar1'), nodeBuilder.is('foo2', 'bar2')]; | ||
const query = toElasticsearchQuery(nodeBuilder.or(nodes)); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo1": "bar1", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo2": "bar2", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('three clauses', () => { | ||
const nodes = [ | ||
nodeBuilder.is('foo1', 'bar1'), | ||
nodeBuilder.is('foo2', 'bar2'), | ||
nodeBuilder.is('foo3', 'bar3'), | ||
]; | ||
const query = toElasticsearchQuery(nodeBuilder.or(nodes)); | ||
expect(query).toMatchInlineSnapshot(` | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo1": "bar1", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo2": "bar2", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object { | ||
"bool": Object { | ||
"minimum_should_match": 1, | ||
"should": Array [ | ||
Object { | ||
"match": Object { | ||
"foo3": "bar3", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.