Skip to content

Commit

Permalink
Extend SearchSource with fieldsApi handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Sep 10, 2020
1 parent 9ed5a95 commit 9c5160f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
QueryStringInput: React.FC<Pick<Props, "query" | "prepend" | "size" | "placeholder" | "onChange" | "onBlur" | "onSubmit" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition" | "onChangeQueryInputFocus">>
React.FC<Pick<Props, "query" | "prepend" | "size" | "className" | "placeholder" | "onChange" | "onBlur" | "onSubmit" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition" | "onChangeQueryInputFocus">>
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface SearchSourceFields
| --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-public.searchsourcefields.aggs.md) | <code>any</code> | |
| [fields](./kibana-plugin-plugins-data-public.searchsourcefields.fields.md) | <code>NameList</code> | |
| [fieldsApi](./kibana-plugin-plugins-data-public.searchsourcefields.fieldsapi.md) | <code>NameList</code> | |
| [filter](./kibana-plugin-plugins-data-public.searchsourcefields.filter.md) | <code>Filter[] &#124; Filter &#124; (() =&gt; Filter[] &#124; Filter &#124; undefined)</code> | |
| [from](./kibana-plugin-plugins-data-public.searchsourcefields.from.md) | <code>number</code> | |
| [highlight](./kibana-plugin-plugins-data-public.searchsourcefields.highlight.md) | <code>any</code> | |
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,8 @@ export interface SearchSourceFields {
// (undocumented)
fields?: NameList;
// (undocumented)
fieldsApi?: NameList;
// (undocumented)
filter?: Filter[] | Filter | (() => Filter[] | Filter | undefined);
// (undocumented)
from?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ export class SearchSource {
case 'fields':
const fields = uniq((data[key] || []).concat(val));
return addToRoot(key, fields);
case 'fieldsApi':
return key && data[key] == null && addToBody('fields', val);
case 'index':
case 'type':
case 'highlightAll':
Expand Down Expand Up @@ -465,7 +467,7 @@ export class SearchSource {

// request the remaining fields from both stored_fields and _source
const remainingFields = difference(fields, keys(body.script_fields));
body.fields = remainingFields;
body.stored_fields = remainingFields;
setWith(body, '_source.includes', remainingFields, (nsValue) =>
isObject(nsValue) ? {} : nsValue
);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/search/search_source/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface SearchSourceFields {
source?: NameList;
version?: boolean;
fields?: NameList;
fieldsApi?: NameList;
index?: IndexPattern;
searchAfter?: EsQuerySearchAfter;
timeout?: string;
Expand Down
15 changes: 5 additions & 10 deletions src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,18 +948,13 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise

$scope.updateDataSource = () => {
const { indexPattern, searchSource } = $scope;
const indexPatternFields = indexPattern.getComputedFields();
const columns = $scope.state.columns.filter((name) => {
return !indexPatternFields.docvalueFields.find((docVal) => docVal.field === name);
});
const fields = [
...columns,
...indexPatternFields.docvalueFields,
...Object.keys(indexPatternFields.scriptFields),
];
const { docvalueFields } = indexPattern.getComputedFields();
const columns = $scope.state.columns.filter(
(name) => !docvalueFields.find((docVal) => docVal.field === name)
);
searchSource
.setField('index', $scope.indexPattern)
.setField('fields', fields)
.setField('fieldsApi', columns)
.setField('source', true)
.setField('size', $scope.opts.sampleSize)
.setField(
Expand Down

0 comments on commit 9c5160f

Please sign in to comment.