Merge pull request #3584 from jdve/fix-conflicted-object-flattening

[indexPattern/flattenSearchResponse] flatten conflicting objects
This commit is contained in:
Spencer 2015-04-14 18:43:43 -07:00
commit 621511c795
2 changed files with 16 additions and 2 deletions

View file

@ -14,7 +14,11 @@ define(function (require) {
key = keyPrefix + key;
if (flat[key] !== void 0) return;
if (fields[key] || !_.isPlainObject(val)) {
var hasValidMapping = (fields[key] && fields[key].type !== 'conflict');
var isValue = !_.isPlainObject(val);
if (hasValidMapping || isValue) {
flat[key] = val;
return;
}

View file

@ -16,6 +16,9 @@ define(function (require) {
'team': { type: 'nested' },
'team.name': { type: 'string' },
'team.role': { type: 'string' },
'user': { type: 'conflict' },
'user.name': { type: 'string' },
'user.id': { type: 'conflict' },
'delta': { type: 'number', scripted: true }
}
}
@ -38,7 +41,8 @@ define(function (require) {
{ name: 'foo', role: 'leader' },
{ name: 'bar', role: 'follower' },
{ name: 'baz', role: 'party boy' },
]
],
user: { name: 'smith', id: 123 }
},
fields: {
delta: [42],
@ -65,6 +69,12 @@ define(function (require) {
expect(flat.groups).to.eql(['loners']);
});
it('flattens conflicting types in the mapping', function () {
expect(flat).to.not.have.property('user');
expect(flat).to.have.property('user.name', hit._source.user.name);
expect(flat).to.have.property('user.id', hit._source.user.id);
});
it('preserves objects in arrays', function () {
expect(flat).to.have.property('tags', hit._source.tags);
});