Merge pull request #8713 from elastic/jasper/backport/7990/5.x

[backport] PR #7990 to 5.x - Display the conflicting field types of an index pattern
This commit is contained in:
Spencer 2016-10-17 14:03:43 -07:00 committed by GitHub
commit 6619b44509
5 changed files with 68 additions and 4 deletions

View file

@ -177,6 +177,25 @@
</div>
<div ng-if="editor.conflictDescriptionsLength > 0">
<p>
<i class="fa fa-warning text-warning"></i>
<strong>Field Type Conflict:</strong>
The type of this field changes across indices. It is unavailable for many analysis functions. The indices per type are as follows:
<table class="table">
<thead>
<th> Field Type </th>
<th> Index Names </th>
</thead>
<tbody>
<tr ng-repeat="(type, indices) in editor.field.conflictDescriptions">
<td>{{type}}</td> <td>{{indices.join(', ')}}</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="form-group">
<button
type="button"

View file

@ -46,6 +46,7 @@ uiModules
self.indexPattern = $scope.getIndexPattern();
self.field = shadowCopy($scope.getField());
self.formatParams = self.field.format.params();
self.conflictDescriptionsLength = (self.field.conflictDescriptions) ? Object.keys(self.field.conflictDescriptions).length : 0;
// only init on first create
self.creating = !self.indexPattern.fields.byName[self.field.name];

View file

@ -0,0 +1,29 @@
import { uniq, where, groupBy, mapValues, pluck } from 'lodash';
export class ConflictTracker {
constructor() {
this._history = [];
}
trackField(name, type, index) {
this._history.push({ name, type, index });
}
describeConflict(name) {
const fieldHistory = where(this._history, { name });
const entriesByType = groupBy(fieldHistory, 'type');
return mapValues(entriesByType, (entries) => {
const indices = uniq(pluck(entries, 'index'));
// keep the list short so we don't polute the .kibana index
if (indices.length > 10) {
const total = indices.length;
indices.length = 9;
indices.push(`... and ${total - indices.length} others`);
}
return indices;
});
}
};

View file

@ -71,6 +71,9 @@ export default function FieldObjectProvider(Private, shortDotsFilter, $rootScope
obj.comp('displayName', shortDotsFilter(spec.name));
obj.comp('$$spec', spec);
// conflict info
obj.writ('conflictDescriptions');
return obj.create();
}

View file

@ -1,9 +1,10 @@
import _ from 'lodash';
import IndexPatternsMapFieldProvider from 'ui/index_patterns/_map_field';
import { ConflictTracker } from 'ui/index_patterns/_conflict_tracker';
export default function transformMappingIntoFields(Private, kbnIndex, config) {
let mapField = Private(IndexPatternsMapFieldProvider);
/**
* Convert the ES response into the simple map for fields to
* mappings which we will cache
@ -15,6 +16,8 @@ export default function transformMappingIntoFields(Private, kbnIndex, config) {
*/
return function (response) {
let fields = {};
const conflictTracker = new ConflictTracker();
_.each(response, function (index, indexName) {
if (indexName === kbnIndex) return;
_.each(index.mappings, function (mappings) {
@ -23,15 +26,19 @@ export default function transformMappingIntoFields(Private, kbnIndex, config) {
if (keys.length === 0 || (name[0] === '_') && !_.contains(config.get('metaFields'), name)) return;
let mapping = mapField(field, name);
// track the name, type and index for every field encountered so that the source
// of conflicts can be described later
conflictTracker.trackField(name, mapping.type, indexName);
if (fields[name]) {
if (fields[name].type !== mapping.type) {
// conflict fields are not available for much except showing in the discover table
mapping.type = 'conflict';
mapping.indexed = false;
// overwrite the entire mapping object to reset all fields
fields[name] = { type: 'conflict' };
}
} else {
fields[name] = _.pick(mapping, 'type', 'indexed', 'analyzed', 'doc_values');
}
fields[name] = _.pick(mapping, 'type', 'indexed', 'analyzed', 'doc_values');
});
});
});
@ -46,6 +53,11 @@ export default function transformMappingIntoFields(Private, kbnIndex, config) {
return _.map(fields, function (mapping, name) {
mapping.name = name;
if (mapping.type === 'conflict') {
mapping.conflictDescriptions = conflictTracker.describeConflict(name);
}
return mapping;
});
};