Skip to content

Commit

Permalink
Merge branch 'main' into 133822-add-doc-link
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jul 26, 2022
2 parents 1f82861 + 038bf2d commit 4e9a2a0
Show file tree
Hide file tree
Showing 314 changed files with 11,217 additions and 7,216 deletions.
1 change: 0 additions & 1 deletion .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ enabled:
- test/interactive_setup_functional/manual_configuration_without_tls.config.ts
- test/interactive_setup_functional/manual_configuration.config.ts
- test/interpreter_functional/config.ts
- test/new_visualize_flow/config.ts
- test/node_roles_functional/all.config.ts
- test/node_roles_functional/background_tasks.config.ts
- test/node_roles_functional/ui.config.ts
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-doc-links/src/get_doc_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export const getDocLinks = ({ kibanaBranch }: GetDocLinkOptions): DocLinks => {
webCrawlerReference: `${APP_SEARCH_DOCS}web-crawler-reference.html`,
},
enterpriseSearch: {
bulkApi: `${ELASTICSEARCH_DOCS}docs-bulk.html`,
configuration: `${ENTERPRISE_SEARCH_DOCS}configuration.html`,
languageAnalyzers: `${ELASTICSEARCH_DOCS}analysis-lang-analyzer.html`,
licenseManagement: `${ENTERPRISE_SEARCH_DOCS}license-management.html`,
mailService: `${ENTERPRISE_SEARCH_DOCS}mailer-configuration.html`,
troubleshootSetup: `${ENTERPRISE_SEARCH_DOCS}troubleshoot-setup.html`,
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export interface DocLinks {
readonly webCrawlerReference: string;
};
readonly enterpriseSearch: {
readonly bulkApi: string;
readonly configuration: string;
readonly languageAnalyzers: string;
readonly licenseManagement: string;
readonly mailService: string;
readonly troubleshootSetup: string;
Expand Down
8 changes: 3 additions & 5 deletions packages/kbn-es-query/grammar/grammar.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ NotListOfValues
Value "value"
= value:QuotedString {
if (value.type === 'cursor') return value;
const isPhrase = buildLiteralNode(true);
return (field) => buildFunctionNode('is', [field, value, isPhrase]);
return (field) => buildFunctionNode('is', [field, value]);
}
/ value:UnquotedLiteral {
if (value.type === 'cursor') return value;
Expand All @@ -193,8 +192,7 @@ Value "value"
error('Leading wildcards are disabled. See query:allowLeadingWildcards in Advanced Settings.');
}

const isPhrase = buildLiteralNode(false);
return (field) => buildFunctionNode('is', [field, value, isPhrase]);
return (field) => buildFunctionNode('is', [field, value]);
}

Or "OR"
Expand Down Expand Up @@ -222,7 +220,7 @@ QuotedString
};
}
/ '"' chars:QuotedCharacter* '"' {
return buildLiteralNode(chars.join(''));
return buildLiteralNode(chars.join(''), true);
}

QuotedCharacter
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-es-query/src/kuery/ast/ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('kuery AST API', () => {
});

test('should treat quoted values as phrases', () => {
const expected = nodeTypes.function.buildNode('is', 'foo', 'bar baz', true);
const expected = nodeTypes.function.buildNode('is', 'foo', '"bar baz"');
const actual = fromKueryExpression('foo:"bar baz"');
expect(actual).toEqual(expected);
});
Expand Down Expand Up @@ -328,19 +328,19 @@ describe('kuery AST API', () => {
test('should support double quoted strings that do not need escapes except for quotes', () => {
const expected = nodeTypes.literal.buildNode('\\():<>"*');
const actual = fromLiteralExpression('"\\():<>\\"*"');
expect(actual).toEqual(expected);
expect(actual.value).toEqual(expected.value);
});

test('should support escaped backslashes inside quoted strings', () => {
const expected = nodeTypes.literal.buildNode('\\');
const actual = fromLiteralExpression('"\\\\"');
expect(actual).toEqual(expected);
expect(actual.value).toEqual(expected.value);
});

test('should support escaped unicode sequences inside quoted strings', () => {
const expected = nodeTypes.literal.buildNode('\\u00A0');
const actual = fromLiteralExpression('"\\\\u00A0"');
expect(actual).toEqual(expected);
expect(actual.value).toEqual(expected.value);
});

test('should detect wildcards and build wildcard AST nodes', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/kbn-es-query/src/kuery/functions/is.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ describe('kuery functions', () => {

test('should default to a non-phrase query', () => {
const {
arguments: [, , isPhrase],
arguments: [, value],
} = is.buildNodeParams('response', 200);
expect(isPhrase.value).toBe(false);
expect(value.isQuoted).toBe(false);
});

test('should allow specification of a phrase query', () => {
const {
arguments: [, , isPhrase],
} = is.buildNodeParams('response', 200, true);
expect(isPhrase.value).toBe(true);
arguments: [, value],
} = is.buildNodeParams('response', '"200"');
expect(value.isQuoted).toBe(true);
});
});

Expand Down Expand Up @@ -180,7 +180,7 @@ describe('kuery functions', () => {
minimum_should_match: 1,
},
};
const node = nodeTypes.function.buildNode('is', 'extension', 'jpg', true);
const node = nodeTypes.function.buildNode('is', 'extension', '"jpg"');
const result = is.toElasticsearchQuery(node, indexPattern);

expect(result).toEqual(expected);
Expand Down
9 changes: 4 additions & 5 deletions packages/kbn-es-query/src/kuery/functions/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as ast from '../ast';
import * as literal from '../node_types/literal';
import * as wildcard from '../node_types/wildcard';

export function buildNodeParams(fieldName: string, value: any, isPhrase: boolean = false) {
export function buildNodeParams(fieldName: string, value: any) {
if (isUndefined(fieldName)) {
throw new Error('fieldName is a required argument');
}
Expand All @@ -32,9 +32,8 @@ export function buildNodeParams(fieldName: string, value: any, isPhrase: boolean
: literal.buildNode(fieldName);
const valueNode =
typeof value === 'string' ? ast.fromLiteralExpression(value) : literal.buildNode(value);
const isPhraseNode = literal.buildNode(isPhrase);
return {
arguments: [fieldNode, valueNode, isPhraseNode],
arguments: [fieldNode, valueNode],
};
}

Expand All @@ -45,7 +44,7 @@ export function toElasticsearchQuery(
context: KqlContext = {}
): estypes.QueryDslQueryContainer {
const {
arguments: [fieldNameArg, valueArg, isPhraseArg],
arguments: [fieldNameArg, valueArg],
} = node;

const isExistsQuery = wildcard.isNode(valueArg) && wildcard.isLoneWildcard(valueArg);
Expand All @@ -62,7 +61,7 @@ export function toElasticsearchQuery(
context?.nested ? context.nested.path : undefined
);
const value = !isUndefined(valueArg) ? ast.toElasticsearchQuery(valueArg) : valueArg;
const type = isPhraseArg.value ? 'phrase' : 'best_fields';
const type = valueArg.isQuoted ? 'phrase' : 'best_fields';
if (fullFieldNameArg.value === null) {
if (wildcard.isNode(valueArg)) {
return {
Expand Down
8 changes: 3 additions & 5 deletions packages/kbn-es-query/src/kuery/grammar/__mocks__/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ function peg$parse(input, options) {
};
var peg$f15 = function(value) {
if (value.type === 'cursor') return value;
const isPhrase = buildLiteralNode(true);
return (field) => buildFunctionNode('is', [field, value, isPhrase]);
return (field) => buildFunctionNode('is', [field, value]);
};
var peg$f16 = function(value) {
if (value.type === 'cursor') return value;
Expand All @@ -377,8 +376,7 @@ function peg$parse(input, options) {
error('Leading wildcards are disabled. See query:allowLeadingWildcards in Advanced Settings.');
}

const isPhrase = buildLiteralNode(false);
return (field) => buildFunctionNode('is', [field, value, isPhrase]);
return (field) => buildFunctionNode('is', [field, value]);
};
var peg$f17 = function() { return parseCursor; };
var peg$f18 = function(prefix, cursor, suffix) {
Expand All @@ -393,7 +391,7 @@ function peg$parse(input, options) {
};
};
var peg$f19 = function(chars) {
return buildLiteralNode(chars.join(''));
return buildLiteralNode(chars.join(''), true);
};
var peg$f20 = function(char) { return char; };
var peg$f21 = function(chars) {
Expand Down
4 changes: 3 additions & 1 deletion packages/kbn-es-query/src/kuery/node_types/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ export type KqlLiteralType = null | boolean | number | string;
export interface KqlLiteralNode extends KueryNode {
type: typeof KQL_NODE_TYPE_LITERAL;
value: KqlLiteralType;
isQuoted: boolean;
}

export function isNode(node: KueryNode): node is KqlLiteralNode {
return node.type === KQL_NODE_TYPE_LITERAL;
}

export function buildNode(value: KqlLiteralType): KqlLiteralNode {
export function buildNode(value: KqlLiteralType, isQuoted: boolean = false): KqlLiteralNode {
return {
type: KQL_NODE_TYPE_LITERAL,
value,
isQuoted,
};
}

Expand Down
1 change: 0 additions & 1 deletion packages/kbn-es-query/src/kuery/node_types/node_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const nodeBuilder = {
return nodeTypes.function.buildNodeWithArgumentNodes('is', [
nodeTypes.literal.buildNode(fieldName),
typeof value === 'string' ? nodeTypes.literal.buildNode(value) : value,
nodeTypes.literal.buildNode(false),
]);
},
or: (nodes: KueryNode[]): KueryNode => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,14 @@ describe('Filter Utils', () => {
expect(
validateConvertFilterToKueryNode(
['foo'],
esKuery.nodeTypes.function.buildNode('is', `foo.attributes.title`, 'best', true),
esKuery.nodeTypes.function.buildNode('is', `foo.attributes.title`, '"best"'),
mockMappings
)
).toEqual(esKuery.fromKueryExpression('foo.title: "best"'));
});

test('does not mutate the input KueryNode', () => {
const input = esKuery.nodeTypes.function.buildNode(
'is',
`foo.attributes.title`,
'best',
true
);
const input = esKuery.nodeTypes.function.buildNode('is', `foo.attributes.title`, '"best"');

const inputCopy = cloneDeep(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ describe('findSharedOriginObjects', () => {
[obj1, obj2, obj3].forEach(({ type, origin }, i) => {
expect(kueryFilterArgs[i * 2].arguments).toEqual(
expect.arrayContaining([
{ type: 'literal', value: `${type}.id` },
{ type: 'literal', value: `${type}:${origin}` },
{ type: 'literal', value: `${type}.id`, isQuoted: false },
{ type: 'literal', value: `${type}:${origin}`, isQuoted: false },
])
);
expect(kueryFilterArgs[i * 2 + 1].arguments).toEqual(
expect.arrayContaining([
{ type: 'literal', value: `${type}.originId` },
{ type: 'literal', value: origin },
{ type: 'literal', value: `${type}.originId`, isQuoted: false },
{ type: 'literal', value: origin, isQuoted: false },
])
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ describe('findLegacyUrlAliases', () => {
const typeAndIdFilter = typeAndIdFilters[i].arguments;
expect(typeAndIdFilter).toEqual([
expect.objectContaining({
arguments: expect.arrayContaining([{ type: 'literal', value: type }]),
arguments: expect.arrayContaining([{ type: 'literal', value: type, isQuoted: false }]),
}),
expect.objectContaining({
arguments: expect.arrayContaining([{ type: 'literal', value: id }]),
arguments: expect.arrayContaining([{ type: 'literal', value: id, isQuoted: false }]),
}),
]);
});
Expand Down
10 changes: 2 additions & 8 deletions src/core/server/saved_objects/service/lib/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3764,17 +3764,14 @@ describe('SavedObjectsRepository', () => {
Object {
"arguments": Array [
Object {
"isQuoted": false,
"type": "literal",
"value": "dashboard.otherField",
},
Object {
"type": "wildcard",
"value": "@kuery-wildcard@",
},
Object {
"type": "literal",
"value": false,
},
],
"function": "is",
"type": "function",
Expand Down Expand Up @@ -3804,17 +3801,14 @@ describe('SavedObjectsRepository', () => {
Object {
"arguments": Array [
Object {
"isQuoted": false,
"type": "literal",
"value": "dashboard.otherField",
},
Object {
"type": "wildcard",
"value": "@kuery-wildcard@",
},
Object {
"type": "literal",
"value": false,
},
],
"function": "is",
"type": "function",
Expand Down
Loading

0 comments on commit 4e9a2a0

Please sign in to comment.