Skip to content

Commit

Permalink
[7.x] [Query] Es query/field base (#103177) (#103872)
Browse files Browse the repository at this point in the history
* [Query] Es query/field base (#103177)

* remove es query dependency on format.convert

* FieldBase

* fix types

* types

* Fix type imports

* test types

* fix jest

* rename

* docs

* comment

* docs

Co-authored-by: Liza Katz <lizka.k@gmail.com>
Co-authored-by: Liza K <liza.katz@elastic.co>
  • Loading branch information
3 people authored Jun 30, 2021
1 parent 627ee17 commit 30819d4
Show file tree
Hide file tree
Showing 42 changed files with 130 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ esFilters: {
FILTERS: typeof FILTERS;
FilterStateStore: typeof FilterStateStore;
buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("../common").Filter;
buildPhrasesFilter: (field: import("../common").IFieldType, params: any[], indexPattern: import("../common").IndexPatternBase) => import("../common").PhrasesFilter;
buildExistsFilter: (field: import("../common").IFieldType, indexPattern: import("../common").IndexPatternBase) => import("../common").ExistsFilter;
buildPhraseFilter: (field: import("../common").IFieldType, value: any, indexPattern: import("../common").IndexPatternBase) => import("../common").PhraseFilter;
buildPhrasesFilter: (field: import("../common").IndexPatternFieldBase, params: any[], indexPattern: import("../common").IndexPatternBase) => import("../common").PhrasesFilter;
buildExistsFilter: (field: import("../common").IndexPatternFieldBase, indexPattern: import("../common").IndexPatternBase) => import("../common").ExistsFilter;
buildPhraseFilter: (field: import("../common").IndexPatternFieldBase, value: any, indexPattern: import("../common").IndexPatternBase) => import("../common").PhraseFilter;
buildQueryFilter: (query: any, index: string, alias: string) => import("../common").QueryStringFilter;
buildRangeFilter: (field: import("../common").IFieldType, params: import("../common").RangeFilterParams, indexPattern: import("../common").IndexPatternBase, formattedValue?: string | undefined) => import("../common").RangeFilter;
buildRangeFilter: (field: import("../common").IndexPatternFieldBase, params: import("../common").RangeFilterParams, indexPattern: import("../common").IndexPatternBase, formattedValue?: string | undefined) => import("../common").RangeFilter;
isPhraseFilter: (filter: any) => filter is import("../common").PhraseFilter;
isExistsFilter: (filter: any) => filter is import("../common").ExistsFilter;
isPhrasesFilter: (filter: any) => filter is import("../common").PhrasesFilter;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<b>Signature:</b>

```typescript
export interface IFieldType
export interface IFieldType extends IndexPatternFieldBase
```
## Properties
Expand All @@ -26,15 +26,9 @@ export interface IFieldType
| [esTypes](./kibana-plugin-plugins-data-public.ifieldtype.estypes.md) | <code>string[]</code> | |
| [filterable](./kibana-plugin-plugins-data-public.ifieldtype.filterable.md) | <code>boolean</code> | |
| [format](./kibana-plugin-plugins-data-public.ifieldtype.format.md) | <code>any</code> | |
| [lang](./kibana-plugin-plugins-data-public.ifieldtype.lang.md) | <code>estypes.ScriptLanguage</code> | |
| [name](./kibana-plugin-plugins-data-public.ifieldtype.name.md) | <code>string</code> | |
| [readFromDocValues](./kibana-plugin-plugins-data-public.ifieldtype.readfromdocvalues.md) | <code>boolean</code> | |
| [script](./kibana-plugin-plugins-data-public.ifieldtype.script.md) | <code>string</code> | |
| [scripted](./kibana-plugin-plugins-data-public.ifieldtype.scripted.md) | <code>boolean</code> | |
| [searchable](./kibana-plugin-plugins-data-public.ifieldtype.searchable.md) | <code>boolean</code> | |
| [sortable](./kibana-plugin-plugins-data-public.ifieldtype.sortable.md) | <code>boolean</code> | |
| [subType](./kibana-plugin-plugins-data-public.ifieldtype.subtype.md) | <code>IFieldSubType</code> | |
| [toSpec](./kibana-plugin-plugins-data-public.ifieldtype.tospec.md) | <code>(options?: {</code><br/><code> getFormatterForField?: IndexPattern['getFormatterForField'];</code><br/><code> }) =&gt; FieldSpec</code> | |
| [type](./kibana-plugin-plugins-data-public.ifieldtype.type.md) | <code>string</code> | |
| [visualizable](./kibana-plugin-plugins-data-public.ifieldtype.visualizable.md) | <code>boolean</code> | |

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- 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; [IIndexPattern](./kibana-plugin-plugins-data-public.iindexpattern.md) &gt; [fields](./kibana-plugin-plugins-data-public.iindexpattern.fields.md)

## IIndexPattern.fields property

<b>Signature:</b>

```typescript
fields: IFieldType[];
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface IIndexPattern extends IndexPatternBase
| Property | Type | Description |
| --- | --- | --- |
| [fieldFormatMap](./kibana-plugin-plugins-data-public.iindexpattern.fieldformatmap.md) | <code>Record&lt;string, SerializedFieldFormat&lt;unknown&gt; &#124; undefined&gt;</code> | |
| [fields](./kibana-plugin-plugins-data-public.iindexpattern.fields.md) | <code>IFieldType[]</code> | |
| [getFormatterForField](./kibana-plugin-plugins-data-public.iindexpattern.getformatterforfield.md) | <code>(field: IndexPatternField &#124; IndexPatternField['spec'] &#124; IFieldType) =&gt; FieldFormat</code> | Look up a formatter for a given field |
| [intervalName](./kibana-plugin-plugins-data-public.iindexpattern.intervalname.md) | <code>string &#124; null</code> | |
| [timeFieldName](./kibana-plugin-plugins-data-public.iindexpattern.timefieldname.md) | <code>string</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export declare class IndexPatternField implements IFieldType
| [searchable](./kibana-plugin-plugins-data-public.indexpatternfield.searchable.md) | | <code>boolean</code> | |
| [sortable](./kibana-plugin-plugins-data-public.indexpatternfield.sortable.md) | | <code>boolean</code> | |
| [spec](./kibana-plugin-plugins-data-public.indexpatternfield.spec.md) | | <code>FieldSpec</code> | |
| [subType](./kibana-plugin-plugins-data-public.indexpatternfield.subtype.md) | | <code>import(&quot;../types&quot;).IFieldSubType &#124; undefined</code> | |
| [subType](./kibana-plugin-plugins-data-public.indexpatternfield.subtype.md) | | <code>import(&quot;../..&quot;).IFieldSubType &#124; undefined</code> | |
| [type](./kibana-plugin-plugins-data-public.indexpatternfield.type.md) | | <code>string</code> | |
| [visualizable](./kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md) | | <code>boolean</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
get subType(): import("../types").IFieldSubType | undefined;
get subType(): import("../..").IFieldSubType | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ toJSON(): {
searchable: boolean;
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
subType: import("../..").IFieldSubType | undefined;
customLabel: string | undefined;
};
```
Expand All @@ -37,7 +37,7 @@ toJSON(): {
searchable: boolean;
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
subType: import("../..").IFieldSubType | undefined;
customLabel: string | undefined;
}`

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ esFilters: {
buildQueryFilter: (query: any, index: string, alias: string) => import("../common").QueryStringFilter;
buildCustomFilter: typeof buildCustomFilter;
buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("../common").Filter;
buildExistsFilter: (field: import("../common").IFieldType, indexPattern: import("../common").IndexPatternBase) => import("../common").ExistsFilter;
buildExistsFilter: (field: import("../common").IndexPatternFieldBase, indexPattern: import("../common").IndexPatternBase) => import("../common").ExistsFilter;
buildFilter: typeof buildFilter;
buildPhraseFilter: (field: import("../common").IFieldType, value: any, indexPattern: import("../common").IndexPatternBase) => import("../common").PhraseFilter;
buildPhrasesFilter: (field: import("../common").IFieldType, params: any[], indexPattern: import("../common").IndexPatternBase) => import("../common").PhrasesFilter;
buildRangeFilter: (field: import("../common").IFieldType, params: import("../common").RangeFilterParams, indexPattern: import("../common").IndexPatternBase, formattedValue?: string | undefined) => import("../common").RangeFilter;
buildPhraseFilter: (field: import("../common").IndexPatternFieldBase, value: any, indexPattern: import("../common").IndexPatternBase) => import("../common").PhraseFilter;
buildPhrasesFilter: (field: import("../common").IndexPatternFieldBase, params: any[], indexPattern: import("../common").IndexPatternBase) => import("../common").PhrasesFilter;
buildRangeFilter: (field: import("../common").IndexPatternFieldBase, params: import("../common").RangeFilterParams, indexPattern: import("../common").IndexPatternBase, formattedValue?: string | undefined) => import("../common").RangeFilter;
isFilterDisabled: (filter: import("../common").Filter) => boolean;
}
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<b>Signature:</b>

```typescript
export interface IFieldType
export interface IFieldType extends IndexPatternFieldBase
```
## Properties
Expand All @@ -26,15 +26,9 @@ export interface IFieldType
| [esTypes](./kibana-plugin-plugins-data-server.ifieldtype.estypes.md) | <code>string[]</code> | |
| [filterable](./kibana-plugin-plugins-data-server.ifieldtype.filterable.md) | <code>boolean</code> | |
| [format](./kibana-plugin-plugins-data-server.ifieldtype.format.md) | <code>any</code> | |
| [lang](./kibana-plugin-plugins-data-server.ifieldtype.lang.md) | <code>estypes.ScriptLanguage</code> | |
| [name](./kibana-plugin-plugins-data-server.ifieldtype.name.md) | <code>string</code> | |
| [readFromDocValues](./kibana-plugin-plugins-data-server.ifieldtype.readfromdocvalues.md) | <code>boolean</code> | |
| [script](./kibana-plugin-plugins-data-server.ifieldtype.script.md) | <code>string</code> | |
| [scripted](./kibana-plugin-plugins-data-server.ifieldtype.scripted.md) | <code>boolean</code> | |
| [searchable](./kibana-plugin-plugins-data-server.ifieldtype.searchable.md) | <code>boolean</code> | |
| [sortable](./kibana-plugin-plugins-data-server.ifieldtype.sortable.md) | <code>boolean</code> | |
| [subType](./kibana-plugin-plugins-data-server.ifieldtype.subtype.md) | <code>IFieldSubType</code> | |
| [toSpec](./kibana-plugin-plugins-data-server.ifieldtype.tospec.md) | <code>(options?: {</code><br/><code> getFormatterForField?: IndexPattern['getFormatterForField'];</code><br/><code> }) =&gt; FieldSpec</code> | |
| [type](./kibana-plugin-plugins-data-server.ifieldtype.type.md) | <code>string</code> | |
| [visualizable](./kibana-plugin-plugins-data-server.ifieldtype.visualizable.md) | <code>boolean</code> | |

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import { IFieldType } from '../../index_patterns';
import { Filter } from '../filters';
import { IndexPatternBase } from './types';

Expand All @@ -26,5 +25,5 @@ export function filterMatchesIndex(filter: Filter, indexPattern?: IndexPatternBa
return filter.meta.index === indexPattern.id;
}

return indexPattern.fields.some((field: IFieldType) => field.name === filter.meta.key);
return indexPattern.fields.some((field) => field.name === filter.meta.key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { handleNestedFilter } from './handle_nested_filter';
import { fields } from '../../index_patterns/mocks';
import { buildPhraseFilter, buildQueryFilter } from '../filters';
import { IndexPatternBase } from './types';
import { IFieldType } from '../../index_patterns';

describe('handleNestedFilter', function () {
const indexPattern: IndexPatternBase = {
Expand Down Expand Up @@ -45,8 +44,12 @@ describe('handleNestedFilter', function () {
});

it('should return filter untouched if it does not target a field from the given index pattern', () => {
const field = { ...getField('extension'), name: 'notarealfield' };
const filter = buildPhraseFilter(field as IFieldType, 'jpg', indexPattern);
const field = getField('extension');
const unrealField = {
...field!,
name: 'notarealfield',
};
const filter = buildPhraseFilter(unrealField, 'jpg', indexPattern);
const result = handleNestedFilter(filter, indexPattern);
expect(result).toBe(filter);
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/es_query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export { buildQueryFromFilters } from './from_filters';
export { luceneStringToDsl } from './lucene_string_to_dsl';
export { decorateQuery } from './decorate_query';
export { getEsQueryConfig } from './get_es_query_config';
export { IndexPatternBase } from './types';
export { IndexPatternBase, IndexPatternFieldBase, IFieldSubType } from './types';
27 changes: 25 additions & 2 deletions src/plugins/data/common/es_query/es_query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,32 @@
* Side Public License, v 1.
*/

import { IFieldType } from '../../index_patterns';
import type { estypes } from '@elastic/elasticsearch';

export interface IFieldSubType {
multi?: { parent: string };
nested?: { path: string };
}
export interface IndexPatternFieldBase {
name: string;
/**
* Kibana field type
*/
type: string;
subType?: IFieldSubType;
/**
* Scripted field painless script
*/
script?: string;
/**
* Scripted field langauge
* Painless is the only valid scripted field language
*/
lang?: estypes.ScriptLanguage;
scripted?: boolean;
}

export interface IndexPatternBase {
fields: IFieldType[];
fields: IndexPatternFieldBase[];
id?: string;
}
7 changes: 4 additions & 3 deletions src/plugins/data/common/es_query/filters/build_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import { IFieldType, IndexPatternBase } from '../..';
import { IndexPatternFieldBase, IndexPatternBase } from '../..';

import {
Filter,
FILTERS,
Expand All @@ -20,7 +21,7 @@ import {

export function buildFilter(
indexPattern: IndexPatternBase,
field: IFieldType,
field: IndexPatternFieldBase,
type: FILTERS,
negate: boolean,
disabled: boolean,
Expand Down Expand Up @@ -60,7 +61,7 @@ export function buildCustomFilter(

function buildBaseFilter(
indexPattern: IndexPatternBase,
field: IFieldType,
field: IndexPatternFieldBase,
type: FILTERS,
params: any
): Filter {
Expand Down
Loading

0 comments on commit 30819d4

Please sign in to comment.