mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Merge pull request #3584 from jdve/fix-conflicted-object-flattening
[indexPattern/flattenSearchResponse] flatten conflicting objects
This commit is contained in:
commit
621511c795
2 changed files with 16 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue