Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into task/status-act…
Browse files Browse the repository at this point in the history
…ion-log-text
  • Loading branch information
kevinlog committed Jul 8, 2022
2 parents 84a9842 + 943c366 commit 788df06
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ describe('buildSearchUIConfig', () => {
it('builds a configuration object for Search UI', () => {
const connector = {};
const schema = {
foo: SchemaType.Text,
bar: SchemaType.Number,
foo: {
type: SchemaType.Text,
capabilities: {
snippet: true,
facet: true,
},
},
bar: {
type: SchemaType.Number,
capabilities: {
snippet: false,
facet: false,
},
},
};
const fields = {
filterFields: ['fieldA', 'fieldB'],
filterFields: ['foo', 'bar'],
sortFields: [],
};

Expand All @@ -32,13 +44,9 @@ describe('buildSearchUIConfig', () => {
sortField: 'id',
},
searchQuery: {
disjunctiveFacets: ['fieldA', 'fieldB'],
disjunctiveFacets: ['foo'],
facets: {
fieldA: {
size: 30,
type: 'value',
},
fieldB: {
foo: {
size: 30,
type: 'value',
},
Expand All @@ -50,7 +58,6 @@ describe('buildSearchUIConfig', () => {
foo: {
raw: {},
snippet: {
fallback: true,
size: 300,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,44 @@

import type { APIConnector, SortDirection } from '@elastic/search-ui';

import { Schema } from '../../../../shared/schema/types';
import { SchemaType, AdvancedSchema } from '../../../../shared/schema/types';

import { Fields } from './types';

export const buildSearchUIConfig = (
apiConnector: APIConnector,
schema: Schema,
schema: AdvancedSchema,
fields: Fields,
initialState = { sortDirection: 'desc' as SortDirection, sortField: 'id' }
) => {
const facets = fields.filterFields.reduce((facetsConfig, fieldName) => {
// Geolocation fields do not support value facets https://www.elastic.co/guide/en/app-search/current/facets.html
if (schema[fieldName] === 'geolocation') {
return facetsConfig;
}
return {
...facetsConfig,
[fieldName]: { type: 'value', size: 30 },
};
}, {});
const facets = fields.filterFields
.filter((fieldName) => !!schema[fieldName] && schema[fieldName].type !== SchemaType.Geolocation)
.filter((fieldName) => !!schema[fieldName].capabilities.facet)
.reduce((facetsConfig, fieldName) => {
return {
...facetsConfig,
[fieldName]: { type: 'value', size: 30 },
};
}, {});

const resultFields = Object.entries(schema)
.filter(([, schemaField]) => schemaField.type !== SchemaType.Nested)
.reduce((acc, [fieldName, schemaField]) => {
if (schemaField.capabilities.snippet) {
return { ...acc, [fieldName]: { raw: {}, snippet: { size: 300 } } };
}
return { ...acc, [fieldName]: { raw: {} } };
}, {});

return {
alwaysSearchOnInitialLoad: true,
apiConnector,
trackUrlState: false,
initialState,
searchQuery: {
disjunctiveFacets: fields.filterFields,
disjunctiveFacets: Object.keys(facets),
facets,
result_fields: Object.keys(schema).reduce((acc: { [key: string]: object }, key: string) => {
if (schema[key] === 'text') {
// Only text fields support snippets
acc[key] = {
snippet: {
size: 300,
fallback: true,
},
raw: {},
};
} else {
acc[key] = {
raw: {},
};
}
return acc;
}, {}),
result_fields: resultFields,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ export const CustomizationModal: React.FC<Props> = ({
sortFields.map(fieldNameToComboBoxOption)
);

const engineSchema = engine.schema || {};
const schema = engine.advancedSchema || {};
const selectableFilterFields = useMemo(
() => Object.keys(engineSchema).map(fieldNameToComboBoxOption),
[engineSchema]
() =>
Object.keys(schema)
.filter((fieldName) => schema[fieldName].capabilities.filter)
.map(fieldNameToComboBoxOption),
[schema]
);
const selectableSortFields = useMemo(
() => Object.keys(engineSchema).map(fieldNameToComboBoxOption),
[engineSchema]
() =>
Object.keys(schema)
.filter((fieldName) => schema[fieldName].capabilities.sort)
.map(fieldNameToComboBoxOption),
[schema]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const SearchExperience: React.FC = () => {

const searchProviderConfig = buildSearchUIConfig(
connector,
engine.schema || {},
engine.advancedSchema || {},
fields,
initialState
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('EngineLogic', () => {
isMeta: false,
invalidBoosts: false,
schema: { test: SchemaType.Text },
advancedSchema: {
test: {
type: SchemaType.Text,
capabilities: {
fulltext: true,
filter: true,
facet: true,
sort: true,
snippet: true,
boost: true,
},
},
},
apiTokens: [],
apiKey: 'some-key',
adaptive_relevance_suggestions_active: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* 2.0.
*/

import { Schema, SchemaConflicts, IIndexingStatus } from '../../../shared/schema/types';
import {
Schema,
SchemaConflicts,
IIndexingStatus,
AdvancedSchema,
} from '../../../shared/schema/types';
import { ApiToken } from '../credentials/types';

export enum EngineTypes {
Expand Down Expand Up @@ -47,6 +52,7 @@ export interface EngineDetails extends Engine {
apiKey: string;
elasticsearchIndexName?: string;
schema: Schema;
advancedSchema: AdvancedSchema;
schemaConflicts?: SchemaConflicts;
unconfirmedFields?: string[];
activeReindexJob?: IIndexingStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const fieldTypeToTokenMap = {
[InternalSchemaType.Location]: 'tokenGeo',
[SchemaType.Date]: 'tokenDate',
[InternalSchemaType.Date]: 'tokenDate',
[InternalSchemaType.Nested]: 'tokenNested',
};

export const ResultToken: React.FC<Props> = ({ fieldType }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export enum SchemaType {
Number = 'number',
Geolocation = 'geolocation',
Date = 'date',
Nested = 'nested',
}
// Certain API endpoints will use these internal type names, which map to the external names above
export enum InternalSchemaType {
String = 'string',
Float = 'float',
Location = 'location',
Date = 'date',
Nested = 'nested',
}

export type Schema = Record<string, SchemaType>;
Expand Down Expand Up @@ -62,3 +64,20 @@ export interface FieldCoercionError {
error: string;
}
export type FieldCoercionErrors = Record<string, FieldCoercionError[]>;

export interface SchemaFieldCapabilities {
fulltext?: boolean;
filter?: boolean;
facet?: boolean;
sort?: boolean;
snippet?: boolean;
boost?: boolean;
}

export interface AdvancedSchemaField {
type: SchemaType;
nestedPath?: string;
capabilities: SchemaFieldCapabilities;
}

export type AdvancedSchema = Record<string, AdvancedSchemaField>;
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const TableRowActions: React.FunctionComponent<{
onClick={(event) => {
onAddRemoveTagsClick((event.target as Element).closest('button')!);
}}
disabled={!agent.active}
key="addRemoveTags"
>
<FormattedMessage
Expand Down
Loading

0 comments on commit 788df06

Please sign in to comment.