mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
bwca for unified search suggestions route (#158796)
## Summary Makes unified search field suggestion route bwca resolves https://github.com/elastic/kibana/issues/157085 - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
e3da05c196
commit
e3c3ba8aeb
5 changed files with 85 additions and 61 deletions
|
@ -65,7 +65,7 @@ export const setupValueSuggestionProvider = (
|
|||
) => {
|
||||
usageCollector?.trackRequest();
|
||||
return core.http
|
||||
.fetch<T>(`/api/kibana/suggestions/values/${index}`, {
|
||||
.fetch<T>(`/internal/kibana/suggestions/values/${index}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
|
@ -75,6 +75,7 @@ export const setupValueSuggestionProvider = (
|
|||
method,
|
||||
}),
|
||||
signal,
|
||||
version: '1',
|
||||
})
|
||||
.then((r) => {
|
||||
usageCollector?.trackResult();
|
||||
|
|
|
@ -16,55 +16,62 @@ import { termsEnumSuggestions } from './terms_enum';
|
|||
import { termsAggSuggestions } from './terms_agg';
|
||||
|
||||
export function registerValueSuggestionsRoute(router: IRouter, config$: Observable<ConfigSchema>) {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/kibana/suggestions/values/{index}',
|
||||
validate: {
|
||||
params: schema.object(
|
||||
{
|
||||
index: schema.string(),
|
||||
},
|
||||
{ unknowns: 'allow' }
|
||||
),
|
||||
body: schema.object(
|
||||
{
|
||||
field: schema.string(),
|
||||
query: schema.string(),
|
||||
filters: schema.maybe(schema.any()),
|
||||
fieldMeta: schema.maybe(schema.any()),
|
||||
method: schema.maybe(
|
||||
schema.oneOf([schema.literal('terms_agg'), schema.literal('terms_enum')])
|
||||
router.versioned
|
||||
.post({
|
||||
path: '/internal/kibana/suggestions/values/{index}',
|
||||
access: 'internal',
|
||||
})
|
||||
.addVersion(
|
||||
{
|
||||
version: '1',
|
||||
validate: {
|
||||
request: {
|
||||
params: schema.object(
|
||||
{
|
||||
index: schema.string(),
|
||||
},
|
||||
{ unknowns: 'allow' }
|
||||
),
|
||||
body: schema.object(
|
||||
{
|
||||
field: schema.string(),
|
||||
query: schema.string(),
|
||||
filters: schema.maybe(schema.any()),
|
||||
fieldMeta: schema.maybe(schema.any()),
|
||||
method: schema.maybe(
|
||||
schema.oneOf([schema.literal('terms_agg'), schema.literal('terms_enum')])
|
||||
),
|
||||
},
|
||||
{ unknowns: 'allow' }
|
||||
),
|
||||
},
|
||||
{ unknowns: 'allow' }
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
async (context, request, response) => {
|
||||
const config = await firstValueFrom(config$);
|
||||
const { field: fieldName, query, filters, fieldMeta, method } = request.body;
|
||||
const { index } = request.params;
|
||||
const abortSignal = getRequestAbortedSignal(request.events.aborted$);
|
||||
const { savedObjects, elasticsearch } = await context.core;
|
||||
async (context, request, response) => {
|
||||
const config = await firstValueFrom(config$);
|
||||
const { field: fieldName, query, filters, fieldMeta, method } = request.body;
|
||||
const { index } = request.params;
|
||||
const abortSignal = getRequestAbortedSignal(request.events.aborted$);
|
||||
const { savedObjects, elasticsearch } = await context.core;
|
||||
|
||||
try {
|
||||
const fn = method === 'terms_agg' ? termsAggSuggestions : termsEnumSuggestions;
|
||||
const body = await fn(
|
||||
config,
|
||||
savedObjects.client,
|
||||
elasticsearch.client.asCurrentUser,
|
||||
index,
|
||||
fieldName,
|
||||
query,
|
||||
filters,
|
||||
fieldMeta,
|
||||
abortSignal
|
||||
);
|
||||
return response.ok({ body });
|
||||
} catch (e) {
|
||||
const kbnErr = getKbnServerError(e);
|
||||
return reportServerError(response, kbnErr);
|
||||
try {
|
||||
const fn = method === 'terms_agg' ? termsAggSuggestions : termsEnumSuggestions;
|
||||
const body = await fn(
|
||||
config,
|
||||
savedObjects.client,
|
||||
elasticsearch.client.asCurrentUser,
|
||||
index,
|
||||
fieldName,
|
||||
query,
|
||||
filters,
|
||||
fieldMeta,
|
||||
abortSignal
|
||||
);
|
||||
return response.ok({ body });
|
||||
} catch (e) {
|
||||
const kbnErr = getKbnServerError(e);
|
||||
return reportServerError(response, kbnErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
||||
|
||||
export default function ({ getService }) {
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
@ -32,7 +33,8 @@ export default function ({ getService }) {
|
|||
});
|
||||
it('should return 200 without a query', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
query: '',
|
||||
|
@ -45,7 +47,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 200 without a query and with method set to terms_agg', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
method: 'terms_agg',
|
||||
|
@ -59,7 +62,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 200 without a query and with method set to terms_enum', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
method: 'terms_enum',
|
||||
|
@ -73,7 +77,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 200 with special characters', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
query: '<something?with:lots&of^ bad characters',
|
||||
|
@ -85,7 +90,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should support nested fields', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'nestedField.child',
|
||||
query: 'nes',
|
||||
|
@ -94,7 +100,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 404 if index is not found', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/not_found')
|
||||
.post('/internal/kibana/suggestions/values/not_found')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
query: '1',
|
||||
|
@ -103,7 +110,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 400 without a query', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
})
|
||||
|
@ -111,7 +119,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 400 with a bad method', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/basic_index')
|
||||
.post('/internal/kibana/suggestions/values/basic_index')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'baz.keyword',
|
||||
query: '',
|
||||
|
@ -138,7 +147,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('filter is applied on a document level with terms_agg', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/logstash-*')
|
||||
.post('/internal/kibana/suggestions/values/logstash-*')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'extension.raw',
|
||||
query: '',
|
||||
|
@ -163,7 +173,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('filter returns all results because it was applied on an index level with terms_enum', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/logstash-*')
|
||||
.post('/internal/kibana/suggestions/values/logstash-*')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'extension.raw',
|
||||
query: '',
|
||||
|
@ -188,7 +199,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('filter is applied on an index level with terms_enum - find in range', () =>
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/logstash-*')
|
||||
.post('/internal/kibana/suggestions/values/logstash-*')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'request.raw',
|
||||
query: '/uploads/anatoly-art',
|
||||
|
@ -212,7 +224,8 @@ export default function ({ getService }) {
|
|||
|
||||
it('filter is applied on an index level with terms_enum - DONT find in range', () => {
|
||||
supertest
|
||||
.post('/api/kibana/suggestions/values/logstash-*')
|
||||
.post('/internal/kibana/suggestions/values/logstash-*')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({
|
||||
field: 'request.raw',
|
||||
query: '/uploads/anatoly-art',
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"@kbn/dev-proc-runner",
|
||||
"@kbn/enterprise-search-plugin",
|
||||
"@kbn/core-saved-objects-server",
|
||||
"@kbn/discover-plugin"
|
||||
"@kbn/discover-plugin",
|
||||
"@kbn/core-http-common"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
|
|||
import expect from '@kbn/expect';
|
||||
import { APM_STATIC_DATA_VIEW_ID } from '@kbn/apm-plugin/common/data_view_constants';
|
||||
import { DataView } from '@kbn/data-views-plugin/common';
|
||||
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
||||
import request from 'superagent';
|
||||
import { FtrProviderContext } from '../../common/ftr_provider_context';
|
||||
import { SupertestReturnType, ApmApiError } from '../../common/apm_api_supertest';
|
||||
|
@ -46,8 +47,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
|
|||
|
||||
function getDataViewSuggestions(field: string) {
|
||||
return supertest
|
||||
.post(`/api/kibana/suggestions/values/${dataViewPattern}`)
|
||||
.post(`/internal/kibana/suggestions/values/${dataViewPattern}`)
|
||||
.set('kbn-xsrf', 'foo')
|
||||
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
||||
.send({ query: '', field, method: 'terms_agg' });
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue