Skip to content

Commit

Permalink
runtime fields rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jun 2, 2021
1 parent bdd7f7e commit 11fe061
Show file tree
Hide file tree
Showing 50 changed files with 1,596 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
Add scripted field to field list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [getRuntimeField](./kibana-plugin-plugins-data-public.indexpattern.getruntimefield.md)

## IndexPattern.getRuntimeField() method

Returns runtime field if exists

<b>Signature:</b>

```typescript
getRuntimeField(name: string): RuntimeField | null;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | |

<b>Returns:</b>

`RuntimeField | null`

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [hasRuntimeField](./kibana-plugin-plugins-data-public.indexpattern.hasruntimefield.md)

## IndexPattern.hasRuntimeField() method

Checks if runtime field exists

<b>Signature:</b>

```typescript
hasRuntimeField(name: string): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | |

<b>Returns:</b>

`boolean`

Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ export declare class IndexPattern implements IIndexPattern
| [getFormatterForField(field)](./kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md) | | Provide a field, get its formatter |
| [getFormatterForFieldNoDefault(fieldname)](./kibana-plugin-plugins-data-public.indexpattern.getformatterforfieldnodefault.md) | | Get formatter for a given field name. Return undefined if none exists |
| [getNonScriptedFields()](./kibana-plugin-plugins-data-public.indexpattern.getnonscriptedfields.md) | | |
| [getRuntimeField(name)](./kibana-plugin-plugins-data-public.indexpattern.getruntimefield.md) | | Returns runtime field if exists |
| [getScriptedFields()](./kibana-plugin-plugins-data-public.indexpattern.getscriptedfields.md) | | |
| [getSourceFiltering()](./kibana-plugin-plugins-data-public.indexpattern.getsourcefiltering.md) | | Get the source filtering configuration for that index. |
| [getTimeField()](./kibana-plugin-plugins-data-public.indexpattern.gettimefield.md) | | |
| [hasRuntimeField(name)](./kibana-plugin-plugins-data-public.indexpattern.hasruntimefield.md) | | Checks if runtime field exists |
| [isTimeBased()](./kibana-plugin-plugins-data-public.indexpattern.istimebased.md) | | |
| [isTimeNanosBased()](./kibana-plugin-plugins-data-public.indexpattern.istimenanosbased.md) | | |
| [removeRuntimeField(name)](./kibana-plugin-plugins-data-public.indexpattern.removeruntimefield.md) | | Remove a runtime field - removed from mapped field or removed unmapped field as appropriate |
| [removeRuntimeField(name, opts)](./kibana-plugin-plugins-data-public.indexpattern.removeruntimefield.md) | | Remove a runtime field - removed from mapped field or removed unmapped field as appropriate |
| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | Remove scripted field from field list |
| [replaceAllRuntimeFields(newFields)](./kibana-plugin-plugins-data-public.indexpattern.replaceallruntimefields.md) | | Replaces all existing runtime fields with new fields |
| [setFieldAttrs(fieldName, attrName, value)](./kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md) | | |
| [setFieldCount(fieldName, count)](./kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md) | | |
| [setFieldCustomLabel(fieldName, customLabel)](./kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md) | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ Remove a runtime field - removed from mapped field or removed unmapped field as
<b>Signature:</b>

```typescript
removeRuntimeField(name: string): void;
removeRuntimeField(name: string, opts?: {
removeFieldFormat: boolean;
removeCustomLabel: boolean;
}): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | |
| opts | <code>{</code><br/><code> removeFieldFormat: boolean;</code><br/><code> removeCustomLabel: boolean;</code><br/><code> }</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
Remove scripted field from field list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [replaceAllRuntimeFields](./kibana-plugin-plugins-data-public.indexpattern.replaceallruntimefields.md)

## IndexPattern.replaceAllRuntimeFields() method

Replaces all existing runtime fields with new fields

<b>Signature:</b>

```typescript
replaceAllRuntimeFields(newFields: Record<string, RuntimeField>): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| newFields | <code>Record&lt;string, RuntimeField&gt;</code> | |

<b>Returns:</b>

`void`

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
Add scripted field to field list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) &gt; [getRuntimeField](./kibana-plugin-plugins-data-server.indexpattern.getruntimefield.md)

## IndexPattern.getRuntimeField() method

Returns runtime field if exists

<b>Signature:</b>

```typescript
getRuntimeField(name: string): RuntimeField | null;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | |

<b>Returns:</b>

`RuntimeField | null`

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) &gt; [hasRuntimeField](./kibana-plugin-plugins-data-server.indexpattern.hasruntimefield.md)

## IndexPattern.hasRuntimeField() method

Checks if runtime field exists

<b>Signature:</b>

```typescript
hasRuntimeField(name: string): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | |

<b>Returns:</b>

`boolean`

Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ export declare class IndexPattern implements IIndexPattern
| [getFormatterForField(field)](./kibana-plugin-plugins-data-server.indexpattern.getformatterforfield.md) | | Provide a field, get its formatter |
| [getFormatterForFieldNoDefault(fieldname)](./kibana-plugin-plugins-data-server.indexpattern.getformatterforfieldnodefault.md) | | Get formatter for a given field name. Return undefined if none exists |
| [getNonScriptedFields()](./kibana-plugin-plugins-data-server.indexpattern.getnonscriptedfields.md) | | |
| [getRuntimeField(name)](./kibana-plugin-plugins-data-server.indexpattern.getruntimefield.md) | | Returns runtime field if exists |
| [getScriptedFields()](./kibana-plugin-plugins-data-server.indexpattern.getscriptedfields.md) | | |
| [getSourceFiltering()](./kibana-plugin-plugins-data-server.indexpattern.getsourcefiltering.md) | | Get the source filtering configuration for that index. |
| [getTimeField()](./kibana-plugin-plugins-data-server.indexpattern.gettimefield.md) | | |
| [hasRuntimeField(name)](./kibana-plugin-plugins-data-server.indexpattern.hasruntimefield.md) | | Checks if runtime field exists |
| [isTimeBased()](./kibana-plugin-plugins-data-server.indexpattern.istimebased.md) | | |
| [isTimeNanosBased()](./kibana-plugin-plugins-data-server.indexpattern.istimenanosbased.md) | | |
| [removeRuntimeField(name)](./kibana-plugin-plugins-data-server.indexpattern.removeruntimefield.md) | | Remove a runtime field - removed from mapped field or removed unmapped field as appropriate |
| [removeRuntimeField(name, opts)](./kibana-plugin-plugins-data-server.indexpattern.removeruntimefield.md) | | Remove a runtime field - removed from mapped field or removed unmapped field as appropriate |
| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-server.indexpattern.removescriptedfield.md) | | Remove scripted field from field list |
| [replaceAllRuntimeFields(newFields)](./kibana-plugin-plugins-data-server.indexpattern.replaceallruntimefields.md) | | Replaces all existing runtime fields with new fields |
| [setFieldAttrs(fieldName, attrName, value)](./kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md) | | |
| [setFieldCount(fieldName, count)](./kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md) | | |
| [setFieldCustomLabel(fieldName, customLabel)](./kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md) | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ Remove a runtime field - removed from mapped field or removed unmapped field as
<b>Signature:</b>

```typescript
removeRuntimeField(name: string): void;
removeRuntimeField(name: string, opts?: {
removeFieldFormat: boolean;
removeCustomLabel: boolean;
}): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | |
| opts | <code>{</code><br/><code> removeFieldFormat: boolean;</code><br/><code> removeCustomLabel: boolean;</code><br/><code> }</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> use runtime field instead
>
Remove scripted field from field list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) &gt; [replaceAllRuntimeFields](./kibana-plugin-plugins-data-server.indexpattern.replaceallruntimefields.md)

## IndexPattern.replaceAllRuntimeFields() method

Replaces all existing runtime fields with new fields

<b>Signature:</b>

```typescript
replaceAllRuntimeFields(newFields: Record<string, RuntimeField>): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| newFields | <code>Record&lt;string, RuntimeField&gt;</code> | |

<b>Returns:</b>

`void`

Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ export class IndexPattern implements IIndexPattern {
* @param name Field name
* @param runtimeField Runtime field definition
*/

addRuntimeField(name: string, runtimeField: RuntimeField) {
const existingField = this.getFieldByName(name);
if (existingField) {
Expand All @@ -383,22 +382,65 @@ export class IndexPattern implements IIndexPattern {
this.runtimeFieldMap[name] = runtimeField;
}

/**
* Checks if runtime field exists
* @param name
*/
hasRuntimeField(name: string): boolean {
return !!this.runtimeFieldMap[name];
}

/**
* Returns runtime field if exists
* @param name
*/
getRuntimeField(name: string): RuntimeField | null {
return this.runtimeFieldMap[name] ?? null;
}

/**
* Replaces all existing runtime fields with new fields
* @param newFields
*/
replaceAllRuntimeFields(newFields: Record<string, RuntimeField>) {
const oldRuntimeFieldNames = Object.keys(this.runtimeFieldMap);
oldRuntimeFieldNames.forEach((name) => {
this.removeRuntimeField(name, { removeCustomLabel: false, removeFieldFormat: false });
});

Object.entries(newFields).forEach(([name, field]) => {
this.addRuntimeField(name, field);
});
}

/**
* Remove a runtime field - removed from mapped field or removed unmapped
* field as appropriate
* @param name Field name
* @param opts specify additional removal options
*/

removeRuntimeField(name: string) {
removeRuntimeField(
name: string,
opts: { removeFieldFormat: boolean; removeCustomLabel: boolean } = {
removeCustomLabel: true,
removeFieldFormat: true,
}
) {
const existingField = this.getFieldByName(name);
if (existingField) {
if (existingField.isMapped) {
// mapped field, remove runtimeField def
existingField.runtimeField = undefined;
} else {
// runtimeField only
this.setFieldCustomLabel(name, null);
this.deleteFieldFormat(name);
if (opts.removeCustomLabel) {
this.setFieldCustomLabel(name, null);
}

if (opts.removeFieldFormat) {
this.deleteFieldFormat(name);
}

this.fields.remove(existingField);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1368,13 +1368,15 @@ export class IndexPattern implements IIndexPattern {
typeMeta?: string | undefined;
type?: string | undefined;
};
getRuntimeField(name: string): RuntimeField | null;
// @deprecated (undocumented)
getScriptedFields(): IndexPatternField[];
getSourceFiltering(): {
excludes: any[];
};
// (undocumented)
getTimeField(): IndexPatternField | undefined;
hasRuntimeField(name: string): boolean;
// (undocumented)
id?: string;
// @deprecated (undocumented)
Expand All @@ -1385,9 +1387,13 @@ export class IndexPattern implements IIndexPattern {
isTimeNanosBased(): boolean;
// (undocumented)
metaFields: string[];
removeRuntimeField(name: string): void;
removeRuntimeField(name: string, opts?: {
removeFieldFormat: boolean;
removeCustomLabel: boolean;
}): void;
// @deprecated
removeScriptedField(fieldName: string): void;
replaceAllRuntimeFields(newFields: Record<string, RuntimeField>): void;
resetOriginalSavedObjectBody: () => void;
// (undocumented)
protected setFieldAttrs<K extends keyof FieldAttrSet>(fieldName: string, attrName: K, value: FieldAttrSet[K]): void;
Expand Down
Loading

0 comments on commit 11fe061

Please sign in to comment.