Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Experimental usage of ES fields API - wildcard fields #77722

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2039,6 +2039,8 @@ export interface SearchSourceFields {
// (undocumented)
fields?: NameList;
// (undocumented)
fieldsApi?: NameList;
// (undocumented)
filter?: Filter[] | Filter | (() => Filter[] | Filter | undefined);
// (undocumented)
from?: number;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/search_source/search_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,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
8 changes: 6 additions & 2 deletions src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise
$scope.state = { ...newState };

// detect changes that should trigger fetching of new data
const changes = ['interval', 'sort'].filter(
const changes = ['interval', 'sort', 'columns'].filter(
(prop) => !_.isEqual(newStatePartial[prop], oldStatePartial[prop])
);

Expand Down Expand Up @@ -863,7 +863,9 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise
}

$scope.hits = resp.hits.total;
$scope.rows = resp.hits.hits;
$scope.rows = resp.hits.hits.map((hit) => {
return { ...hit, ...{ _source: hit.fields } };
});

// if we haven't counted yet, reset the counts
const counts = ($scope.fieldCounts = $scope.fieldCounts || {});
Expand Down Expand Up @@ -940,6 +942,8 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise
const { indexPattern, searchSource } = $scope;
searchSource
.setField('index', $scope.indexPattern)
.setField('fieldsApi', ['*'])
.setField('source', false)
Comment on lines +945 to +946
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@majagrubic all fields are requested instead of source

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it's the opposite of #75407 where _source is requested and selected fields are added to the requests, here no additional request is needed when columns are added to the table

.setField('size', $scope.opts.sampleSize)
.setField(
'sort',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ export function createTableRowDirective($compile: ng.ICompileService, $httpParam
$compile($detailsTr)($detailsScope);
};

$scope.$watchMulti(['indexPattern.timeFieldName', 'row.highlight', '[]columns'], () => {
createSummaryRow($scope.row);
});
$scope.$watchMulti(
['indexPattern.timeFieldName', 'row.highlight', '[]columns', 'row'],
() => {
createSummaryRow($scope.row);
}
);

$scope.inlineFilter = function inlineFilter($event: any, type: string) {
const column = $($event.target).data().column;
Expand Down Expand Up @@ -174,6 +177,7 @@ export function createTableRowDirective($compile: ng.ICompileService, $httpParam
let $cells = $el.children();
newHtmls.forEach(function (html, i) {
const $cell = $cells.eq(i);

if ($cell.data('discover:html') === html) return;

const reuse = find($cells.slice(i + 1), function (cell: any) {
Expand Down