forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Add essql search strategy and integrate in canvas (el…
…astic#94754)"" This reverts commit 0f15a12.
- Loading branch information
1 parent
0f15a12
commit 5b0cf6d
Showing
33 changed files
with
603 additions
and
18 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
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
94 changes: 94 additions & 0 deletions
94
x-pack/plugins/canvas/canvas_plugin_src/functions/browser/escount.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,94 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
ExpressionFunctionDefinition, | ||
ExpressionValueFilter, | ||
} from 'src/plugins/expressions/common'; | ||
|
||
// @ts-expect-error untyped local | ||
import { buildESRequest } from '../../../common/lib/request/build_es_request'; | ||
|
||
import { searchService } from '../../../public/services'; | ||
|
||
import { getFunctionHelp } from '../../../i18n'; | ||
|
||
interface Arguments { | ||
index: string | null; | ||
query: string; | ||
} | ||
|
||
export function escount(): ExpressionFunctionDefinition< | ||
'escount', | ||
ExpressionValueFilter, | ||
Arguments, | ||
any | ||
> { | ||
const { help, args: argHelp } = getFunctionHelp().escount; | ||
|
||
return { | ||
name: 'escount', | ||
type: 'number', | ||
context: { | ||
types: ['filter'], | ||
}, | ||
help, | ||
args: { | ||
query: { | ||
types: ['string'], | ||
aliases: ['_', 'q'], | ||
help: argHelp.query, | ||
default: '"-_index:.kibana"', | ||
}, | ||
index: { | ||
types: ['string'], | ||
default: '_all', | ||
help: argHelp.index, | ||
}, | ||
}, | ||
fn: (input, args, handlers) => { | ||
input.and = input.and.concat([ | ||
{ | ||
type: 'filter', | ||
filterType: 'luceneQueryString', | ||
query: args.query, | ||
and: [], | ||
}, | ||
]); | ||
|
||
const esRequest = buildESRequest( | ||
{ | ||
index: args.index, | ||
body: { | ||
track_total_hits: true, | ||
size: 0, | ||
query: { | ||
bool: { | ||
must: [{ match_all: {} }], | ||
}, | ||
}, | ||
}, | ||
}, | ||
input | ||
); | ||
|
||
const search = searchService.getService().search; | ||
const req = { | ||
params: { | ||
...esRequest, | ||
}, | ||
}; | ||
|
||
return search | ||
.search(req) | ||
.toPromise() | ||
.then((resp: any) => { | ||
return resp.rawResponse.hits.total; | ||
}); | ||
}, | ||
}; | ||
} |
141 changes: 141 additions & 0 deletions
141
x-pack/plugins/canvas/canvas_plugin_src/functions/browser/esdocs.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,141 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
ExpressionFunctionDefinition, | ||
ExpressionValueFilter, | ||
} from 'src/plugins/expressions/common'; | ||
|
||
// @ts-expect-error untyped local | ||
import { buildESRequest } from '../../../common/lib/request/build_es_request'; | ||
|
||
import { searchService } from '../../../public/services'; | ||
import { ESSQL_SEARCH_STRATEGY } from '../../../common/lib/constants'; | ||
import { EssqlSearchStrategyRequest, EssqlSearchStrategyResponse } from '../../../types'; | ||
import { getFunctionHelp } from '../../../i18n'; | ||
|
||
interface Arguments { | ||
index: string; | ||
query: string; | ||
sort: string; | ||
fields: string; | ||
metaFields: string; | ||
count: number; | ||
} | ||
|
||
export function esdocs(): ExpressionFunctionDefinition< | ||
'esdocs', | ||
ExpressionValueFilter, | ||
Arguments, | ||
any | ||
> { | ||
const { help, args: argHelp } = getFunctionHelp().esdocs; | ||
|
||
return { | ||
name: 'esdocs', | ||
type: 'datatable', | ||
context: { | ||
types: ['filter'], | ||
}, | ||
help, | ||
args: { | ||
query: { | ||
types: ['string'], | ||
aliases: ['_', 'q'], | ||
help: argHelp.query, | ||
default: '-_index:.kibana', | ||
}, | ||
count: { | ||
types: ['number'], | ||
default: 1000, | ||
help: argHelp.count, | ||
}, | ||
fields: { | ||
help: argHelp.fields, | ||
types: ['string'], | ||
}, | ||
index: { | ||
types: ['string'], | ||
default: '_all', | ||
help: argHelp.index, | ||
}, | ||
// TODO: This arg isn't being used in the function. | ||
// We need to restore this functionality or remove it as an arg. | ||
metaFields: { | ||
help: argHelp.metaFields, | ||
types: ['string'], | ||
}, | ||
sort: { | ||
types: ['string'], | ||
help: argHelp.sort, | ||
}, | ||
}, | ||
fn: async (input, args, handlers) => { | ||
const { count, index, fields, sort } = args; | ||
|
||
input.and = input.and.concat([ | ||
{ | ||
type: 'filter', | ||
filterType: 'luceneQueryString', | ||
query: args.query, | ||
and: [], | ||
}, | ||
]); | ||
|
||
// Load ad-hoc to avoid adding to the page load bundle size | ||
const squel = await import('squel'); | ||
|
||
let query = squel.select({ | ||
autoQuoteTableNames: true, | ||
autoQuoteFieldNames: true, | ||
autoQuoteAliasNames: true, | ||
nameQuoteCharacter: '"', | ||
}); | ||
|
||
if (index) { | ||
query.from(index); | ||
} | ||
|
||
if (fields) { | ||
const allFields = fields.split(',').map((field) => field.trim()); | ||
allFields.forEach((field) => (query = query.field(field))); | ||
} | ||
|
||
if (sort) { | ||
const [sortField, sortOrder] = sort.split(',').map((str) => str.trim()); | ||
if (sortField) { | ||
query.order(`"${sortField}"`, sortOrder === 'asc'); | ||
} | ||
} | ||
|
||
const search = searchService.getService().search; | ||
|
||
const req = { | ||
count, | ||
query: query.toString(), | ||
filter: input.and, | ||
}; | ||
|
||
// We're requesting the data using the ESSQL strategy because | ||
// the SQL routes return type information with the result set | ||
return search | ||
.search<EssqlSearchStrategyRequest, EssqlSearchStrategyResponse>(req, { | ||
strategy: ESSQL_SEARCH_STRATEGY, | ||
}) | ||
.toPromise() | ||
.then((resp: EssqlSearchStrategyResponse) => { | ||
return { | ||
type: 'datatable', | ||
meta: { | ||
type: 'essql', | ||
}, | ||
...resp, | ||
}; | ||
}); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.