[6.x] Move buildEsQuery to a package (#26306)

* Move buildEsQuery to a package (#23345)

* fix: move buildEsQuery to utils

* fix: tests that I broke

* fix: add back link to the docs

* fix: don't export from ui/ and link to utils

* fix: move to a package

* fix: move error to errors.js

* fix: paths for peg task

* fix: update reference to kuery

* fix: build step for transpilation

* fix: add typescript declaration file

* fix: test

* tmp: debug individual tests

* debug: add debug stuff for reporting tests

* try to debug test

* Testing splitting reporting jobs in two

* Testing splitting each job

* Fix ci yaml

* Skipping job to check failing test

* debug - adding a catch to jobResponseHandler on report

* Testing a different job and enabling verbose mode

* Testing verbose on phantom_api skipping other CI tests

* Fix script mode

* fix: try running tests in chromium

* fix: move out of devDependencies

* fix: remove commented test

* Revert "fix: try running tests in chromium"

This reverts commit 991d46f051.

* Revert testing changes

* Fixing build for phantomjs

* Revert CI configuration to master. Remove verbose logging for tests

* remove x-pack/yarn.lock, accidentally added back in #23345

* Fix import sorting
This commit is contained in:
Lukas Olson 2018-12-18 13:52:33 -07:00 committed by GitHub
parent d53a9a295f
commit e23dc042b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 2927 additions and 351 deletions

View file

@ -9,8 +9,6 @@ bower_components
/src/fixtures/vislib/mock_data
/src/ui/public/angular-bootstrap
/src/ui/public/flot-charts
/src/ui/public/kuery/ast/kuery.js
/src/ui/public/kuery/ast/legacy_kuery.js
/test/fixtures/scenarios
/src/legacy/core_plugins/console/public/webpackShims
/src/legacy/core_plugins/console/public/tests/webpackShims
@ -20,6 +18,8 @@ bower_components
/packages/*/target
/packages/eslint-config-kibana
/packages/eslint-plugin-kibana-custom
/packages/kbn-es-query/src/kuery/ast/kuery.js
/packages/kbn-es-query/src/kuery/ast/legacy_kuery.js
/packages/kbn-pm/dist
/packages/kbn-plugin-generator/sao_template/template
/packages/kbn-ui-framework/dist

View file

@ -117,6 +117,7 @@
"@kbn/babel-code-parser": "1.0.0",
"@kbn/babel-preset": "1.0.0",
"@kbn/config-schema": "1.0.0",
"@kbn/es-query": "1.0.0",
"@kbn/i18n": "1.0.0",
"@kbn/interpreter": "1.0.0",
"@kbn/pm": "1.0.0",

View file

@ -0,0 +1,3 @@
{
"presets": ["@kbn/babel-preset/webpack_preset"]
}

View file

@ -17,4 +17,4 @@
* under the License.
*/
export * from 'ui/kuery/ast';
export * from './src';

View file

@ -0,0 +1,20 @@
{
"name": "@kbn/es-query",
"main": "target/index.js",
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "babel src --out-dir target",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},
"dependencies": {
"lodash": "npm:@elastic/lodash@3.10.1-kibana1"
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"babel-cli": "^6.26.0",
"expect.js": "0.3.1"
}
}

View file

@ -0,0 +1,5 @@
{
"meta": {
"index": "logstash-*"
}
}

View file

@ -1,4 +1,5 @@
{
"id": "logstash-*",
"title": "logstash-*",
"fields": [
{

View file

@ -17,26 +17,23 @@
* under the License.
*/
import expect from 'expect.js';
import { BuildESQueryProvider } from '../build_es_query';
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import ngMock from 'ng_mock';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
import { fromKueryExpression, toElasticsearchQuery } from '../../../../kuery';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import { fromKueryExpression, toElasticsearchQuery } from '../../kuery';
import { luceneStringToDsl } from '../lucene_string_to_dsl';
import { decorateQuery } from '../../decorate_query';
import { decorateQuery } from '../decorate_query';
let indexPattern;
let buildEsQuery;
const configStub = { get: () => ({}) };
const privateStub = fn => fn(configStub);
describe('build query', function () {
describe('buildESQuery', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(StubbedLogstashIndexPatternProvider);
buildEsQuery = Private(BuildESQueryProvider);
}));
beforeEach(() => {
buildEsQuery = privateStub(BuildESQueryProvider);
});
it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildEsQuery();
@ -48,7 +45,7 @@ describe('build query', function () {
must_not: [],
}
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should combine queries and filters from multiple query languages into a single ES bool query', function () {
@ -66,7 +63,7 @@ describe('build query', function () {
const expectedResult = {
bool: {
must: [
decorateQuery(luceneStringToDsl('bar:baz')),
decorateQuery(luceneStringToDsl('bar:baz'), configStub),
{ match_all: {} },
],
filter: [
@ -79,7 +76,7 @@ describe('build query', function () {
const result = buildEsQuery(indexPattern, queries, filters);
expectDeepEqual(result, expectedResult);
expect(result).to.eql(expectedResult);
});
});

View file

@ -18,19 +18,19 @@
*/
import expect from 'expect.js';
import chrome from '../../../chrome';
import { decorateQuery } from '../decorate_query';
const config = chrome.getUiSettingsClient();
describe('Query decorator', function () {
const configStub = {
get: () => ({ analyze_wildcard: true })
};
describe('Query decorator', function () {
it('should be a function', function () {
expect(decorateQuery).to.be.a(Function);
});
it('should merge in the query string options', function () {
config.set('query:queryString:options', { analyze_wildcard: true });
const decoratedQuery = decorateQuery({ query_string: { query: '*' } });
const decoratedQuery = decorateQuery({ query_string: { query: '*' } }, configStub);
expect(decoratedQuery).to.eql({ query_string: { query: '*', analyze_wildcard: true } });
});
});

View file

@ -17,14 +17,12 @@
* under the License.
*/
import expect from 'expect.js';
import { buildQueryFromFilters } from '../from_filters';
import { decorateQuery } from '../../decorate_query.js';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
describe('build query', function () {
describe('buildQueryFromFilters', function () {
it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildQueryFromFilters([]);
const expected = {
@ -33,7 +31,7 @@ describe('build query', function () {
should: [],
must_not: [],
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should transform an array of kibana filters into ES queries combined in the bool clauses', function () {
@ -53,9 +51,9 @@ describe('build query', function () {
{ exists: { field: 'foo' } }
];
const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);
expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});
it('should place negated filters in the must_not clause', function () {
@ -70,9 +68,9 @@ describe('build query', function () {
{ match_all: {} },
];
const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);
expectDeepEqual(result.must_not, expectedESQueries);
expect(result.must_not).to.eql(expectedESQueries);
});
it('should translate old ES filter syntax into ES 5+ query objects', function () {
@ -89,9 +87,9 @@ describe('build query', function () {
}
];
const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);
expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});
it('should migrate deprecated match syntax', function () {
@ -108,11 +106,9 @@ describe('build query', function () {
}
];
const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);
expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});
});
});

View file

@ -18,24 +18,14 @@
*/
import { buildQueryFromKuery } from '../from_kuery';
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import ngMock from 'ng_mock';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import expect from 'expect.js';
import { fromKueryExpression, toElasticsearchQuery } from '../../../../kuery';
let indexPattern;
import { fromKueryExpression, toElasticsearchQuery } from '../../kuery';
describe('build query', function () {
const configStub = { get: () => true };
describe('buildQueryFromKuery', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(StubbedLogstashIndexPatternProvider);
}));
it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildQueryFromKuery(null, [], configStub);
const expected = {
@ -44,7 +34,7 @@ describe('build query', function () {
should: [],
must_not: [],
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should transform an array of kuery queries into ES queries combined in the bool\'s filter clause', function () {
@ -61,7 +51,7 @@ describe('build query', function () {
const result = buildQueryFromKuery(indexPattern, queries, configStub);
expectDeepEqual(result.filter, expectedESQueries);
expect(result.filter).to.eql(expectedESQueries);
});
it('should throw a useful error if it looks like query is using an old, unsupported syntax', function () {

View file

@ -17,11 +17,12 @@
* under the License.
*/
import expect from 'expect.js';
import { buildQueryFromLucene } from '../from_lucene';
import { decorateQuery } from '../../decorate_query';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal';
import { decorateQuery } from '../decorate_query';
import { luceneStringToDsl } from '../lucene_string_to_dsl';
const configStub = { get: () => ({}) };
describe('build query', function () {
@ -35,7 +36,7 @@ describe('build query', function () {
should: [],
must_not: [],
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should transform an array of lucene queries into ES queries combined in the bool\'s must clause', function () {
@ -46,13 +47,13 @@ describe('build query', function () {
const expectedESQueries = queries.map(
(query) => {
return decorateQuery(luceneStringToDsl(query.query));
return decorateQuery(luceneStringToDsl(query.query), configStub);
}
);
const result = buildQueryFromLucene(queries, decorateQuery);
const result = buildQueryFromLucene(queries, configStub);
expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});
it('should also accept queries in ES query DSL format, simply passing them through', function () {
@ -60,9 +61,9 @@ describe('build query', function () {
{ query: { match_all: {} }, language: 'lucene' },
];
const result = buildQueryFromLucene(queries, decorateQuery);
const result = buildQueryFromLucene(queries, configStub);
expectDeepEqual(result.must, [queries[0].query]);
expect(result.must).to.eql([queries[0].query]);
});
});

View file

@ -18,7 +18,6 @@
*/
import { luceneStringToDsl } from '../lucene_string_to_dsl';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
import expect from 'expect.js';
describe('build query', function () {
@ -30,7 +29,7 @@ describe('build query', function () {
const expectedResult = {
query_string: { query: 'foo:bar' }
};
expectDeepEqual(result, expectedResult);
expect(result).to.eql(expectedResult);
});
it('should return a match_all query for empty strings and whitespace', function () {
@ -38,15 +37,15 @@ describe('build query', function () {
match_all: {}
};
expectDeepEqual(luceneStringToDsl(''), expectedResult);
expectDeepEqual(luceneStringToDsl(' '), expectedResult);
expect(luceneStringToDsl('')).to.eql(expectedResult);
expect(luceneStringToDsl(' ')).to.eql(expectedResult);
});
it('should return non-string arguments without modification', function () {
const expectedResult = {};
const result = luceneStringToDsl(expectedResult);
expect(result).to.be(expectedResult);
expectDeepEqual(result, expectedResult);
expect(result).to.eql(expectedResult);
});
});

View file

@ -18,7 +18,6 @@
*/
import { groupBy, has } from 'lodash';
import { decorateQuery } from '../decorate_query';
import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
@ -35,8 +34,8 @@ export function BuildESQueryProvider(config) {
const queriesByLanguage = groupBy(validQueries, 'language');
const kueryQuery = buildQueryFromKuery(indexPattern, queriesByLanguage.kuery, config);
const luceneQuery = buildQueryFromLucene(queriesByLanguage.lucene, decorateQuery);
const filterQuery = buildQueryFromFilters(filters, decorateQuery, indexPattern);
const luceneQuery = buildQueryFromLucene(queriesByLanguage.lucene, config);
const filterQuery = buildQueryFromFilters(filters, indexPattern, config);
return {
bool: {

View file

@ -18,17 +18,14 @@
*/
import _ from 'lodash';
import chrome from 'ui/chrome';
const config = chrome.getUiSettingsClient();
/**
* Decorate queries with default parameters
* @param {query} query object
* @returns {object}
*/
export function decorateQuery(query) {
const queryOptions = config.get('query:queryString:options');
export function decorateQuery(query, config) {
const queryOptions = config ? config.get('query:queryString:options') : {};
if (_.has(query, 'query_string.query')) {
_.extend(query.query_string, queryOptions);

View file

@ -18,7 +18,8 @@
*/
import _ from 'lodash';
import { migrateFilter } from '../migrate_filter';
import { migrateFilter } from './migrate_filter';
import { decorateQuery } from './decorate_query';
/**
* Create a filter that can be reversed for filters with negate set
@ -58,10 +59,10 @@ const cleanFilter = function (filter) {
return _.omit(filter, ['meta', '$state']);
};
export function buildQueryFromFilters(filters, decorateQuery, indexPattern) {
export function buildQueryFromFilters(filters, indexPattern, config) {
_.each(filters, function (filter) {
if (filter.query) {
decorateQuery(filter.query);
decorateQuery(filter.query, config);
}
});

View file

@ -17,33 +17,20 @@
* under the License.
*/
import { fromLegacyKueryExpression, fromKueryExpression, toElasticsearchQuery, nodeTypes } from '../../../kuery';
import { documentationLinks } from '../../../documentation_links';
import { NoLeadingWildcardsError } from '../../../kuery/errors';
const queryDocs = documentationLinks.query;
import { fromLegacyKueryExpression, fromKueryExpression, toElasticsearchQuery, nodeTypes } from '../kuery';
export function buildQueryFromKuery(indexPattern, queries = [], config) {
const allowLeadingWildcards = config.get('query:allowLeadingWildcards');
const queryASTs = queries.map((query) => {
const queryASTs = queries.map(query => {
try {
return fromKueryExpression(query.query, { allowLeadingWildcards });
}
catch (parseError) {
if (parseError instanceof NoLeadingWildcardsError) {
throw parseError;
}
} catch (parseError) {
try {
fromLegacyKueryExpression(query.query);
}
catch (legacyParseError) {
} catch (legacyParseError) {
throw parseError;
}
throw new Error(
`It looks like you're using an outdated Kuery syntax. See what changed in the [docs](${queryDocs.kueryQuerySyntax})!`
);
throw Error('OutdatedKuerySyntaxError');
}
});
return buildQuery(indexPattern, queryASTs);

View file

@ -18,12 +18,13 @@
*/
import _ from 'lodash';
import { decorateQuery } from './decorate_query';
import { luceneStringToDsl } from './lucene_string_to_dsl';
export function buildQueryFromLucene(queries, decorateQuery) {
export function buildQueryFromLucene(queries, config) {
const combinedQueries = _.map(queries, (query) => {
const queryDsl = luceneStringToDsl(query.query);
return decorateQuery(queryDsl);
return decorateQuery(queryDsl, config);
});
return {

View file

@ -20,3 +20,5 @@
export { BuildESQueryProvider } from './build_es_query';
export { buildQueryFromFilters } from './from_filters';
export { luceneStringToDsl } from './lucene_string_to_dsl';
export { migrateFilter } from './migrate_filter';
export { decorateQuery } from './decorate_query';

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { getConvertedValueForField } from '../../filter_manager/lib/phrase';
import { getConvertedValueForField } from '../filters';
export function migrateFilter(filter, indexPattern) {
if (filter.match) {

View file

@ -21,25 +21,23 @@
import { buildInlineScriptForPhraseFilter, buildPhraseFilter } from '../phrase';
import expect from 'expect.js';
import _ from 'lodash';
import ngMock from 'ng_mock';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import filterSkeleton from '../../__fixtures__/filter_skeleton';
let indexPattern;
let expected;
describe('Filter Manager', function () {
describe('Phrase filter builder', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
expected = _.cloneDeep(require('fixtures/filter_skeleton'));
}));
beforeEach(() => {
expected = _.cloneDeep(filterSkeleton);
});
it('should be a function', function () {
expect(buildPhraseFilter).to.be.a(Function);
});
it('should return a match query filter when passed a standard field', function () {
const field = getField(indexPattern, 'bytes');
expected.query = {
match: {
bytes: {
@ -48,19 +46,20 @@ describe('Filter Manager', function () {
}
}
};
expect(buildPhraseFilter(indexPattern.fields.byName.bytes, 5, indexPattern)).to.eql(expected);
expect(buildPhraseFilter(field, 5, indexPattern)).to.eql(expected);
});
it('should return a script filter when passed a scripted field', function () {
const field = getField(indexPattern, 'script number');
expected.meta.field = 'script number';
_.set(expected, 'script.script', {
inline: '(' + indexPattern.fields.byName['script number'].script + ') == value',
inline: '(' + field.script + ') == value',
lang: 'expression',
params: {
value: 5,
}
});
expect(buildPhraseFilter(indexPattern.fields.byName['script number'], 5, indexPattern)).to.eql(expected);
expect(buildPhraseFilter(field, 5, indexPattern)).to.eql(expected);
});
});
@ -90,3 +89,7 @@ describe('Filter Manager', function () {
});
});
});
function getField(indexPattern, name) {
return indexPattern.fields.find(field => field.name === name);
}

View file

@ -18,21 +18,18 @@
*/
import { buildQueryFilter } from '../query';
import { cloneDeep } from 'lodash';
import expect from 'expect.js';
import _ from 'lodash';
import ngMock from 'ng_mock';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import filterSkeleton from '../../__fixtures__/filter_skeleton';
let indexPattern;
let expected;
describe('Filter Manager', function () {
describe('Phrase filter builder', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
expected = _.cloneDeep(require('fixtures/filter_skeleton'));
}));
beforeEach(() => {
expected = cloneDeep(filterSkeleton);
});
it('should be a function', function () {
expect(buildQueryFilter).to.be.a(Function);

View file

@ -20,78 +20,77 @@
import { buildRangeFilter } from '../range';
import expect from 'expect.js';
import _ from 'lodash';
import ngMock from 'ng_mock';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import filterSkeleton from '../../__fixtures__/filter_skeleton';
let indexPattern;
let expected;
describe('Filter Manager', function () {
describe('Range filter builder', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
expected = _.cloneDeep(require('fixtures/filter_skeleton'));
}));
beforeEach(() => {
expected = _.cloneDeep(filterSkeleton);
});
it('should be a function', function () {
expect(buildRangeFilter).to.be.a(Function);
});
it('should return a range filter when passed a standard field', function () {
const field = getField(indexPattern, 'bytes');
expected.range = {
bytes: {
gte: 1,
lte: 3
}
};
expect(buildRangeFilter(indexPattern.fields.byName.bytes, { gte: 1, lte: 3 }, indexPattern)).to.eql(expected);
expect(buildRangeFilter(field, { gte: 1, lte: 3 }, indexPattern)).to.eql(expected);
});
it('should return a script filter when passed a scripted field', function () {
const field = getField(indexPattern, 'script number');
expected.meta.field = 'script number';
_.set(expected, 'script.script', {
lang: 'expression',
inline: '(' + indexPattern.fields.byName['script number'].script + ')>=gte && (' +
indexPattern.fields.byName['script number'].script + ')<=lte',
inline: '(' + field.script + ')>=gte && (' + field.script + ')<=lte',
params: {
value: '>=1 <=3',
gte: 1,
lte: 3
}
});
expect(buildRangeFilter(
indexPattern.fields.byName['script number'], { gte: 1, lte: 3 }, indexPattern)).to.eql(expected);
expect(buildRangeFilter(field, { gte: 1, lte: 3 }, indexPattern)).to.eql(expected);
});
it('should wrap painless scripts in comparator lambdas', function () {
const field = getField(indexPattern, 'script date');
const expected = `boolean gte(Supplier s, def v) {return s.get() >= v} ` +
`boolean lte(Supplier s, def v) {return s.get() <= v}` +
`gte(() -> { ${indexPattern.fields.byName['script date'].script} }, params.gte) && ` +
`lte(() -> { ${indexPattern.fields.byName['script date'].script} }, params.lte)`;
`gte(() -> { ${field.script} }, params.gte) && ` +
`lte(() -> { ${field.script} }, params.lte)`;
const inlineScript = buildRangeFilter(
indexPattern.fields.byName['script date'], { gte: 1, lte: 3 }, indexPattern).script.script.inline;
const inlineScript = buildRangeFilter(field, { gte: 1, lte: 3 }, indexPattern).script.script.inline;
expect(inlineScript).to.be(expected);
});
it('should throw an error when gte and gt, or lte and lt are both passed', function () {
const field = getField(indexPattern, 'script number');
expect(function () {
buildRangeFilter(indexPattern.fields.byName['script number'], { gte: 1, gt: 3 }, indexPattern);
buildRangeFilter(field, { gte: 1, gt: 3 }, indexPattern);
}).to.throwError();
expect(function () {
buildRangeFilter(indexPattern.fields.byName['script number'], { lte: 1, lt: 3 }, indexPattern);
buildRangeFilter(field, { lte: 1, lt: 3 }, indexPattern);
}).to.throwError();
});
it('to use the right operator for each of gte, gt, lt and lte', function () {
const field = getField(indexPattern, 'script number');
_.each({ gte: '>=', gt: '>', lte: '<=', lt: '<' }, function (operator, key) {
const params = {};
params[key] = 5;
const filter = buildRangeFilter(indexPattern.fields.byName['script number'], params, indexPattern);
const filter = buildRangeFilter(field, params, indexPattern);
expect(filter.script.script.inline).to.be(
'(' + indexPattern.fields.byName['script number'].script + ')' + operator + key);
'(' + field.script + ')' + operator + key);
expect(filter.script.script.params[key]).to.be(5);
expect(filter.script.script.params.value).to.be(operator + 5);
@ -99,9 +98,10 @@ describe('Filter Manager', function () {
});
describe('when given params where one side is infinite', function () {
const field = getField(indexPattern, 'script number');
let filter;
beforeEach(function () {
filter = buildRangeFilter(indexPattern.fields.byName['script number'], { gte: 0, lt: Infinity }, indexPattern);
filter = buildRangeFilter(field, { gte: 0, lt: Infinity }, indexPattern);
});
describe('returned filter', function () {
@ -118,17 +118,19 @@ describe('Filter Manager', function () {
});
it('does not contain a script condition for the infinite side', function () {
const script = indexPattern.fields.byName['script number'].script;
const field = getField(indexPattern, 'script number');
const script = field.script;
expect(filter.script.script.inline).to.equal(`(${script})>=gte`);
});
});
});
describe('when given params where both sides are infinite', function () {
const field = getField(indexPattern, 'script number');
let filter;
beforeEach(function () {
filter = buildRangeFilter(
indexPattern.fields.byName['script number'], { gte: -Infinity, lt: Infinity }, indexPattern);
field, { gte: -Infinity, lt: Infinity }, indexPattern);
});
describe('returned filter', function () {
@ -148,3 +150,7 @@ describe('Filter Manager', function () {
});
});
});
function getField(indexPattern, name) {
return indexPattern.fields.find(field => field.name === name);
}

View file

@ -0,0 +1,24 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export * from './exists';
export * from './phrase';
export * from './phrases';
export * from './query';
export * from './range';

View file

@ -24,7 +24,7 @@ export function buildPhrasesFilter(field, params, indexPattern) {
const type = 'phrases';
const key = field.name;
const value = params
.map(value => field.format.convert(value))
.map(value => format(field, value))
.join(', ');
const filter = {
@ -53,3 +53,9 @@ export function buildPhrasesFilter(field, params, indexPattern) {
return filter;
}
function format(field, value) {
return field && field.format && field.format.convert
? field.format.convert(value)
: value;
}

View file

@ -33,7 +33,7 @@ const comparators = {
};
function formatValue(field, params) {
return _.map(params, (val, key) => operators[key] + field.format.convert(val)).join(' ');
return _.map(params, (val, key) => operators[key] + format(field, val)).join(' ');
}
export function buildRangeFilter(field, params, indexPattern, formattedValue) {
@ -102,3 +102,10 @@ export function getRangeScript(field, params) {
}
};
}
function format(field, value) {
return field && field.format && field.format.convert
? field.format.convert(value)
: value;
}

View file

@ -17,4 +17,4 @@
* under the License.
*/
export * from 'ui/kuery/ast/ast';
export * from './kuery';

View file

@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export * from './kuery';
export * from './filters';
export * from './es_query';

View file

@ -20,10 +20,7 @@
import * as ast from '../ast';
import expect from 'expect.js';
import { nodeTypes } from '../../node_types/index';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal.js';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
// Helpful utility allowing us to test the PEG parser by simply checking for deep equality between
// the nodes the parser generates and the nodes our constructor functions generate.
@ -62,19 +59,19 @@ describe('kuery AST API', function () {
it('should return a match all "is" function for whitespace', function () {
const expected = nodeTypes.function.buildNode('is', '*', '*');
const actual = fromLegacyKueryExpressionNoMeta(' ');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should return an "and" function for single literals', function () {
const expected = nodeTypes.function.buildNode('and', [nodeTypes.literal.buildNode('foo')]);
const actual = fromLegacyKueryExpressionNoMeta('foo');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should ignore extraneous whitespace at the beginning and end of the query', function () {
const expected = nodeTypes.function.buildNode('and', [nodeTypes.literal.buildNode('foo')]);
const actual = fromLegacyKueryExpressionNoMeta(' foo ');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('literals and queries separated by whitespace should be joined by an implicit "and"', function () {
@ -83,7 +80,7 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('bar'),
]);
const actual = fromLegacyKueryExpressionNoMeta('foo bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should also support explicit "and"s as a binary operator', function () {
@ -92,7 +89,7 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('bar'),
]);
const actual = fromLegacyKueryExpressionNoMeta('foo and bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should also support "and" as a function', function () {
@ -101,7 +98,7 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('bar'),
], 'function');
const actual = fromLegacyKueryExpressionNoMeta('and(foo, bar)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support "or" as a binary operator', function () {
@ -110,7 +107,7 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('bar'),
]);
const actual = fromLegacyKueryExpressionNoMeta('foo or bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support "or" as a function', function () {
@ -119,7 +116,7 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('bar'),
]);
const actual = fromLegacyKueryExpressionNoMeta('or(foo, bar)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support negation of queries with a "!" prefix', function () {
@ -129,7 +126,7 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('bar'),
]));
const actual = fromLegacyKueryExpressionNoMeta('!or(foo, bar)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('"and" should have a higher precedence than "or"', function () {
@ -144,7 +141,7 @@ describe('kuery AST API', function () {
])
]);
const actual = fromLegacyKueryExpressionNoMeta('foo or bar and baz or qux');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support grouping to override default precedence', function () {
@ -156,13 +153,13 @@ describe('kuery AST API', function () {
nodeTypes.literal.buildNode('baz'),
]);
const actual = fromLegacyKueryExpressionNoMeta('(foo or bar) and baz');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support a shorthand operator syntax for "is" functions', function () {
const expected = nodeTypes.function.buildNode('is', 'foo', 'bar', true);
const actual = fromLegacyKueryExpressionNoMeta('foo:bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support a shorthand operator syntax for inclusive "range" functions', function () {
@ -173,13 +170,13 @@ describe('kuery AST API', function () {
];
const expected = nodeTypes.function.buildNodeWithArgumentNodes('range', argumentNodes);
const actual = fromLegacyKueryExpressionNoMeta('bytes:[1000 to 8000]');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support functions with named arguments', function () {
const expected = nodeTypes.function.buildNode('range', 'bytes', { gt: 1000, lt: 8000 });
const actual = fromLegacyKueryExpressionNoMeta('range(bytes, gt=1000, lt=8000)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should throw an error for unknown functions', function () {
@ -192,25 +189,25 @@ describe('kuery AST API', function () {
it('should return a match all "is" function for whitespace', function () {
const expected = nodeTypes.function.buildNode('is', '*', '*');
const actual = ast.fromKueryExpression(' ');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should return an "is" function with a null field for single literals', function () {
const expected = nodeTypes.function.buildNode('is', null, 'foo');
const actual = ast.fromKueryExpression('foo');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should ignore extraneous whitespace at the beginning and end of the query', function () {
const expected = nodeTypes.function.buildNode('is', null, 'foo');
const actual = ast.fromKueryExpression(' foo ');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should not split on whitespace', function () {
const expected = nodeTypes.function.buildNode('is', null, 'foo bar');
const actual = ast.fromKueryExpression('foo bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support "and" as a binary operator', function () {
@ -219,7 +216,7 @@ describe('kuery AST API', function () {
nodeTypes.function.buildNode('is', null, 'bar'),
]);
const actual = ast.fromKueryExpression('foo and bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support "or" as a binary operator', function () {
@ -228,7 +225,7 @@ describe('kuery AST API', function () {
nodeTypes.function.buildNode('is', null, 'bar'),
]);
const actual = ast.fromKueryExpression('foo or bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support negation of queries with a "not" prefix', function () {
@ -239,7 +236,7 @@ describe('kuery AST API', function () {
])
);
const actual = ast.fromKueryExpression('not (foo or bar)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('"and" should have a higher precedence than "or"', function () {
@ -254,7 +251,7 @@ describe('kuery AST API', function () {
])
]);
const actual = ast.fromKueryExpression('foo or bar and baz or qux');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support grouping to override default precedence', function () {
@ -266,25 +263,25 @@ describe('kuery AST API', function () {
nodeTypes.function.buildNode('is', null, 'baz'),
]);
const actual = ast.fromKueryExpression('(foo or bar) and baz');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support matching against specific fields', function () {
const expected = nodeTypes.function.buildNode('is', 'foo', 'bar');
const actual = ast.fromKueryExpression('foo:bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should also not split on whitespace when matching specific fields', function () {
const expected = nodeTypes.function.buildNode('is', 'foo', 'bar baz');
const actual = ast.fromKueryExpression('foo:bar baz');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should treat quoted values as phrases', function () {
const expected = nodeTypes.function.buildNode('is', 'foo', 'bar baz', true);
const actual = ast.fromKueryExpression('foo:"bar baz"');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support a shorthand for matching multiple values against a single field', function () {
@ -293,7 +290,7 @@ describe('kuery AST API', function () {
nodeTypes.function.buildNode('is', 'foo', 'baz'),
]);
const actual = ast.fromKueryExpression('foo:(bar or baz)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support "and" and "not" operators and grouping in the shorthand as well', function () {
@ -307,7 +304,7 @@ describe('kuery AST API', function () {
),
]);
const actual = ast.fromKueryExpression('foo:((bar or baz) and not qux)');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support exclusive range operators', function () {
@ -320,7 +317,7 @@ describe('kuery AST API', function () {
}),
]);
const actual = ast.fromKueryExpression('bytes > 1000 and bytes < 8000');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support inclusive range operators', function () {
@ -333,25 +330,25 @@ describe('kuery AST API', function () {
}),
]);
const actual = ast.fromKueryExpression('bytes >= 1000 and bytes <= 8000');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support wildcards in field names', function () {
const expected = nodeTypes.function.buildNode('is', 'machine*', 'osx');
const actual = ast.fromKueryExpression('machine*:osx');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support wildcards in values', function () {
const expected = nodeTypes.function.buildNode('is', 'foo', 'ba*');
const actual = ast.fromKueryExpression('foo:ba*');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should create an exists "is" query when a field is given and "*" is the value', function () {
const expected = nodeTypes.function.buildNode('is', 'foo', '*');
const actual = ast.fromKueryExpression('foo:*');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
});
@ -364,35 +361,35 @@ describe('kuery AST API', function () {
const booleanTrueLiteral = nodeTypes.literal.buildNode(true);
const numberLiteral = nodeTypes.literal.buildNode(42);
expectDeepEqual(ast.fromLiteralExpression('foo'), stringLiteral);
expectDeepEqual(ast.fromLiteralExpression('true'), booleanTrueLiteral);
expectDeepEqual(ast.fromLiteralExpression('false'), booleanFalseLiteral);
expectDeepEqual(ast.fromLiteralExpression('42'), numberLiteral);
expect(ast.fromLiteralExpression('foo')).to.eql(stringLiteral);
expect(ast.fromLiteralExpression('true')).to.eql(booleanTrueLiteral);
expect(ast.fromLiteralExpression('false')).to.eql(booleanFalseLiteral);
expect(ast.fromLiteralExpression('42')).to.eql(numberLiteral);
});
it('should allow escaping of special characters with a backslash', function () {
const expected = nodeTypes.literal.buildNode('\\():<>"*');
// yo dawg
const actual = ast.fromLiteralExpression('\\\\\\(\\)\\:\\<\\>\\"\\*');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support double quoted strings that do not need escapes except for quotes', function () {
const expected = nodeTypes.literal.buildNode('\\():<>"*');
const actual = ast.fromLiteralExpression('"\\():<>\\"*"');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should support escaped backslashes inside quoted strings', function () {
const expected = nodeTypes.literal.buildNode('\\');
const actual = ast.fromLiteralExpression('"\\\\"');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should detect wildcards and build wildcard AST nodes', function () {
const expected = nodeTypes.wildcard.buildNode('foo*bar');
const actual = ast.fromLiteralExpression('foo*bar');
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
});
@ -402,21 +399,21 @@ describe('kuery AST API', function () {
const node = nodeTypes.function.buildNode('exists', 'response');
const expected = nodeTypes.function.toElasticsearchQuery(node, indexPattern);
const result = ast.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should return an empty "and" function for undefined nodes and unknown node types', function () {
const expected = nodeTypes.function.toElasticsearchQuery(nodeTypes.function.buildNode('and', []));
expectDeepEqual(ast.toElasticsearchQuery(), expected);
expect(ast.toElasticsearchQuery()).to.eql(expected);
const noTypeNode = nodeTypes.function.buildNode('exists', 'foo');
delete noTypeNode.type;
expectDeepEqual(ast.toElasticsearchQuery(noTypeNode), expected);
expect(ast.toElasticsearchQuery(noTypeNode)).to.eql(expected);
const unknownTypeNode = nodeTypes.function.buildNode('exists', 'foo');
unknownTypeNode.type = 'notValid';
expectDeepEqual(ast.toElasticsearchQuery(unknownTypeNode), expected);
expect(ast.toElasticsearchQuery(unknownTypeNode)).to.eql(expected);
});
});

View file

@ -19,7 +19,6 @@
import _ from 'lodash';
import { nodeTypes } from '../node_types/index';
import * as errors from '../errors';
import { parse as parseKuery } from './kuery';
import { parse as parseLegacyKuery } from './legacy_kuery';
@ -47,7 +46,7 @@ function fromExpression(expression, parseOptions = {}, parse = parseKuery) {
parseOptions = {
...parseOptions,
helpers: { nodeTypes, errors }
helpers: { nodeTypes }
};
return parse(expression, parseOptions);

View file

@ -17,8 +17,4 @@
* under the License.
*/
export default {
meta: {
index: 'logstash-*'
}
};
export * from '../ast/ast';

View file

@ -154,7 +154,7 @@ module.exports = (function() {
if (value.type === 'cursor') return value;
if (!allowLeadingWildcards && value.type === 'wildcard' && nodeTypes.wildcard.hasLeadingWildcard(value)) {
throw new errors.NoLeadingWildcardsError();
error('Leading wildcards are disabled. See query:allowLeadingWildcards in Advanced Settings.');
}
const isPhrase = buildLiteralNode(false);
@ -1661,7 +1661,7 @@ module.exports = (function() {
}
const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes, errors } } = options;
const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options;
const buildFunctionNode = nodeTypes.function.buildNodeWithArgumentNodes;
const buildLiteralNode = nodeTypes.literal.buildNode;
const buildWildcardNode = nodeTypes.wildcard.buildNode;

View file

@ -5,7 +5,7 @@
// Initialization block
{
const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes, errors } } = options;
const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options;
const buildFunctionNode = nodeTypes.function.buildNodeWithArgumentNodes;
const buildLiteralNode = nodeTypes.literal.buildNode;
const buildWildcardNode = nodeTypes.wildcard.buildNode;
@ -163,7 +163,7 @@ Value
if (value.type === 'cursor') return value;
if (!allowLeadingWildcards && value.type === 'wildcard' && nodeTypes.wildcard.hasLeadingWildcard(value)) {
throw new errors.NoLeadingWildcardsError();
error('Leading wildcards are disabled. See query:allowLeadingWildcards in Advanced Settings.');
}
const isPhrase = buildLiteralNode(false);

View file

@ -20,7 +20,6 @@
import _ from 'lodash';
import expect from 'expect.js';
import { filterToKueryAST } from '../filter_to_kuery';
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal.js';
describe('filter to kuery migration', function () {
@ -63,7 +62,7 @@ describe('filter to kuery migration', function () {
expect(negatedResult).to.have.property('type', 'function');
expect(negatedResult).to.have.property('function', 'not');
expectDeepEqual(negatedResult.arguments[0], result);
expect(negatedResult.arguments[0]).to.eql(result);
});
});

View file

@ -21,7 +21,7 @@ import expect from 'expect.js';
import * as and from '../and';
import { nodeTypes } from '../../node_types';
import * as ast from '../../ast';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;

View file

@ -21,7 +21,7 @@ import expect from 'expect.js';
import * as exists from '../exists';
import { nodeTypes } from '../../node_types';
import _ from 'lodash';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;

View file

@ -20,7 +20,7 @@
import expect from 'expect.js';
import * as geoBoundingBox from '../geo_bounding_box';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;
const params = {

View file

@ -20,7 +20,7 @@
import expect from 'expect.js';
import * as geoPolygon from '../geo_polygon';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;

View file

@ -20,9 +20,7 @@
import expect from 'expect.js';
import * as is from '../is';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;
@ -79,7 +77,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', '*', '*');
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should return an ES multi_match query using default_field when fieldName is null', function () {
@ -93,7 +91,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', null, 200);
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should return an ES query_string query using default_field when fieldName is null and value contains a wildcard', function () {
@ -105,7 +103,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', null, 'jpg*');
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should return an ES bool query with a sub-query for each field when fieldName is "*"', function () {
@ -127,7 +125,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', 'extension', '*');
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should return an ES match query when a concrete fieldName and value are provided', function () {
@ -142,7 +140,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', 'extension', 'jpg');
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should support creation of phrase queries', function () {
@ -157,7 +155,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', 'extension', 'jpg', true);
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should create a query_string query for wildcard values', function () {
@ -177,7 +175,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('is', 'extension', 'jpg*');
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should support scripted fields', function () {

View file

@ -21,7 +21,7 @@ import expect from 'expect.js';
import * as not from '../not';
import { nodeTypes } from '../../node_types';
import * as ast from '../../ast';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;

View file

@ -21,7 +21,7 @@ import expect from 'expect.js';
import * as or from '../or';
import { nodeTypes } from '../../node_types';
import * as ast from '../../ast';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;

View file

@ -18,10 +18,9 @@
*/
import expect from 'expect.js';
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';
import * as range from '../range';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
let indexPattern;
@ -84,7 +83,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('range', 'bytes', { gt: 1000, lt: 8000 });
const result = range.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should support wildcard field names', function () {
@ -106,7 +105,7 @@ describe('kuery functions', function () {
const node = nodeTypes.function.buildNode('range', 'byt*', { gt: 1000, lt: 8000 });
const result = range.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});
it('should support scripted fields', function () {

View file

@ -19,10 +19,9 @@
import { getFields } from '../../utils/get_fields';
import expect from 'expect.js';
import indexPatternResponse from '../../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../../__fixtures__/index_pattern_response.json';
import { nodeTypes } from '../../..';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal';
let indexPattern;
@ -39,7 +38,7 @@ describe('getFields', function () {
const fieldNameNode = nodeTypes.literal.buildNode('nonExistentField');
const expected = [];
const actual = getFields(fieldNameNode, indexPattern);
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should return the single matching field in an array', function () {
@ -69,7 +68,7 @@ describe('getFields', function () {
// ensure the wildcard is not actually being parsed
const expected = [];
const actual = getFields(nodeTypes.literal.buildNode('fo*'), indexPatternWithWildField);
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
});
@ -79,7 +78,7 @@ describe('getFields', function () {
const fieldNameNode = nodeTypes.wildcard.buildNode('nonExistent*');
const expected = [];
const actual = getFields(fieldNameNode, indexPattern);
expectDeepEqual(actual, expected);
expect(actual).to.eql(expected);
});
it('should return all fields that match the pattern in an array', function () {

View file

@ -21,7 +21,7 @@ import _ from 'lodash';
import * as ast from '../ast';
import * as literal from '../node_types/literal';
import * as wildcard from '../node_types/wildcard';
import { getPhraseScript } from '../../filter_manager/lib/phrase';
import { getPhraseScript } from '../../filters';
import { getFields } from './utils/get_fields';
export function buildNodeParams(fieldName, value, isPhrase = false) {

View file

@ -20,7 +20,7 @@
import _ from 'lodash';
import { nodeTypes } from '../node_types';
import * as ast from '../ast';
import { getRangeScript } from '../../filter_manager/lib/range';
import { getRangeScript } from '../../filters';
import { getFields } from './utils/get_fields';
export function buildNodeParams(fieldName, params) {

View file

@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export * from './ast';

View file

@ -20,9 +20,8 @@
import * as functionType from '../function';
import _ from 'lodash';
import expect from 'expect.js';
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal.js';
import * as isFunction from '../../functions/is';
import indexPatternResponse from '../../__tests__/index_pattern_response.json';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
import { nodeTypes } from '../../node_types';
@ -60,7 +59,7 @@ describe('kuery node types', function () {
expect(result).to.have.property('function', 'is');
expect(result).to.have.property('arguments');
expect(result.arguments).to.be(argumentNodes);
expectDeepEqual(result.arguments, argumentNodes);
expect(result.arguments).to.eql(argumentNodes);
});
});

View file

@ -18,7 +18,6 @@
*/
import expect from 'expect.js';
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal.js';
import * as namedArg from '../named_arg';
import { nodeTypes } from '../../node_types';
@ -43,7 +42,7 @@ describe('kuery node types', function () {
const value = nodeTypes.literal.buildNode('foo');
const result = namedArg.buildNode('fieldName', value);
expect(result.value).to.be(value);
expectDeepEqual(result.value, value);
expect(result.value).to.eql(value);
});
});

View file

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": [
"index.d.ts",
"src/**/*.d.ts"
]
}

File diff suppressed because it is too large Load diff

View file

@ -19,8 +19,7 @@
import _ from 'lodash';
import { FilterManager } from './filter_manager.js';
import { buildPhraseFilter } from 'ui/filter_manager/lib/phrase';
import { buildPhrasesFilter } from 'ui/filter_manager/lib/phrases';
import { buildPhraseFilter, buildPhrasesFilter } from '@kbn/es-query';
export class PhraseFilterManager extends FilterManager {
constructor(controlId, fieldName, indexPattern, queryFilter) {

View file

@ -19,7 +19,7 @@
import _ from 'lodash';
import { FilterManager } from './filter_manager.js';
import { buildRangeFilter } from 'ui/filter_manager/lib/range';
import { buildRangeFilter } from '@kbn/es-query';
// Convert slider value into ES range filter
function toRange(sliderValue) {

View file

@ -20,7 +20,7 @@
import { validateInterval } from '../lib/validate_interval';
import { timezoneProvider } from 'ui/vis/lib/timezone';
import { timefilter } from 'ui/timefilter';
import { BuildESQueryProvider } from 'ui/courier';
import { BuildESQueryProvider } from '@kbn/es-query';
const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http, i18n) {
const notify = new Notifier({ location: i18n('tsvb.requestHandler.notifier.locationNameTitle', { defaultMessage: 'Metrics' }) });

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { BuildESQueryProvider } from 'ui/courier';
import { BuildESQueryProvider } from '@kbn/es-query';
import { timezoneProvider } from 'ui/vis/lib/timezone';
const TimelionRequestHandlerProvider = function (Private, Notifier, $http) {

View file

@ -21,7 +21,7 @@ import { VegaParser } from './data_model/vega_parser';
import { SearchCache } from './data_model/search_cache';
import { TimeCache } from './data_model/time_cache';
import { timefilter } from 'ui/timefilter';
import { BuildESQueryProvider } from 'ui/courier';
import { BuildESQueryProvider } from '@kbn/es-query';
export function VegaRequestHandlerProvider(Private, es, serviceSettings) {
const buildEsQuery = Private(BuildESQueryProvider);

View file

@ -26,7 +26,7 @@ import { Utils } from '../data_model/utils';
import { VISUALIZATION_COLORS } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { TooltipHandler } from './vega_tooltip';
import { buildQueryFilter } from 'ui/filter_manager/lib';
import { buildQueryFilter } from '@kbn/es-query';
vega.scheme('elastic', VISUALIZATION_COLORS);

View file

@ -18,9 +18,7 @@
*/
import _ from 'lodash';
import { buildExistsFilter } from '../../filter_manager/lib/exists';
import { buildPhrasesFilter } from '../../filter_manager/lib/phrases';
import { buildQueryFromFilters } from '../../courier';
import { buildExistsFilter, buildPhrasesFilter, buildQueryFromFilters } from '@kbn/es-query';
/**
* walks the aggregation DSL and returns DSL starting at aggregation with id of startFromAggId
@ -151,7 +149,7 @@ const buildOtherBucketAgg = (aggConfigs, aggWithOtherBucket, response) => {
});
resultAgg.filters.filters[key] = {
bool: buildQueryFromFilters(filters, _.noop, indexPattern)
bool: buildQueryFromFilters(filters, indexPattern)
};
};
walkBucketTree(0, response.aggregations, bucketAggs[0].id, [], '');

View file

@ -18,7 +18,7 @@
*/
import moment from 'moment';
import { buildRangeFilter } from '../../../filter_manager/lib/range';
import { buildRangeFilter } from '@kbn/es-query';
export function createFilterDateHistogram(agg, key) {
const start = moment(key);

View file

@ -19,7 +19,7 @@
import chrome from 'ui/chrome';
import { dateRange } from '../../../utils/date_range';
import { buildRangeFilter } from '../../../filter_manager/lib/range';
import { buildRangeFilter } from '@kbn/es-query';
const config = chrome.getUiSettingsClient();

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { buildQueryFilter } from '../../../filter_manager/lib/query';
import { buildQueryFilter } from '@kbn/es-query';
import _ from 'lodash';
export function createFilterFilters(aggConfig, key) {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { buildRangeFilter } from '../../../filter_manager/lib/range';
import { buildRangeFilter } from '@kbn/es-query';
export function createFilterHistogram(aggConfig, key) {
const value = parseInt(key, 10);

View file

@ -18,7 +18,7 @@
*/
import { CidrMask } from '../../../utils/cidr_mask';
import { buildRangeFilter } from '../../../filter_manager/lib/range';
import { buildRangeFilter } from '@kbn/es-query';
export function createFilterIpRange(aggConfig, key) {
let range;

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { buildRangeFilter } from '../../../filter_manager/lib/range';
import { buildRangeFilter } from '@kbn/es-query';
export function createFilterRange(aggConfig, key) {
return buildRangeFilter(

Some files were not shown because too many files have changed in this diff Show more