Skip to content

Commit

Permalink
Merge pull request #8713 from elastic/jasper/backport/7990/5.x
Browse files Browse the repository at this point in the history
[backport] PR #7990 to 5.x - Display the conflicting field types of an index pattern
  • Loading branch information
spalger authored Oct 17, 2016
2 parents 602f897 + a407c7e commit 6619b44
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/ui/public/field_editor/field_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ <h4>

</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"
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
29 changes: 29 additions & 0 deletions src/ui/public/index_patterns/_conflict_tracker.js
Original file line number Diff line number Diff line change
@@ -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;
});
}
};
3 changes: 3 additions & 0 deletions src/ui/public/index_patterns/_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
20 changes: 16 additions & 4 deletions src/ui/public/index_patterns/_transform_mapping_into_fields.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -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');
});
});
});
Expand All @@ -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;
});
};
Expand Down

0 comments on commit 6619b44

Please sign in to comment.