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

[7.x] [Maps] Fix threshold alert issue resolving nested fields (#83577) #83605

Merged
merged 1 commit into from
Nov 18, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function transformResults(
return _.map(subBuckets, (subBucket) => {
const locationFieldResult = _.get(
subBucket,
`entityHits.hits.hits[0].fields.${geoField}[0]`,
`entityHits.hits.hits[0].fields["${geoField}"][0]`,
''
);
const location = locationFieldResult
Expand All @@ -50,7 +50,7 @@ export function transformResults(
: null;
const dateInShape = _.get(
subBucket,
`entityHits.hits.hits[0].fields.${dateField}[0]`,
`entityHits.hits.hits[0].fields["${dateField}"][0]`,
null
);
const docId = _.get(subBucket, `entityHits.hits.hits[0]._id`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,7 @@
"relation" : "gte"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "flight_tracks",
"_id" : "XOng1XQB6yyY-xQxbwWM",
"_score" : 0.0,
"fields" : {
"@timestamp" : [
"2020-09-28T18:01:29.580Z"
]
}
},
{
"_index" : "flight_tracks",
"_id" : "Xeng1XQB6yyY-xQxbwWM",
"_score" : 0.0,
"fields" : {
"@timestamp" : [
"2020-09-28T18:01:29.580Z"
]
}
},
{
"_index" : "flight_tracks",
"_id" : "Xung1XQB6yyY-xQxbwWM",
"_score" : 0.0,
"fields" : {
"@timestamp" : [
"2020-09-28T18:01:29.580Z"
]
}
},
{
"_index" : "flight_tracks",
"_id" : "UOjg1XQB6yyY-xQxZvMz",
"_score" : 0.0,
"fields" : {
"@timestamp" : [
"2020-09-28T18:01:27.266Z"
]
}
}
]
"hits" : []
},
"aggregations" : {
"shapes" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"took" : 2760,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : 0.0,
"hits" : []
},
"aggregations" : {
"shapes" : {
"meta" : { },
"buckets" : {
"0DrJu3QB6yyY-xQxv6Ip" : {
"doc_count" : 1047,
"entitySplit" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 957,
"buckets" : [
{
"key" : "936",
"doc_count" : 9,
"entityHits" : {
"hits" : {
"total" : {
"value" : 9,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "flight_tracks",
"_id" : "N-ng1XQB6yyY-xQxnGSM",
"_score" : null,
"fields" : {
"time_data.@timestamp" : [
"2020-09-28T18:01:41.190Z"
],
"geo.coords.location" : [
"40.62806099653244, -82.8814151789993"
],
"entity_id" : [
"936"
]
},
"sort" : [
1601316101190
]
}
]
}
}
},
{
"key" : "AAL2019",
"doc_count" : 9,
"entityHits" : {
"hits" : {
"total" : {
"value" : 9,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "flight_tracks",
"_id" : "iOng1XQB6yyY-xQxnGSM",
"_score" : null,
"fields" : {
"time_data.@timestamp" : [
"2020-09-28T18:01:41.191Z"
],
"geo.coords.location" : [
"39.006176185794175, -82.22068064846098"
],
"entity_id" : [
"AAL2019"
]
},
"sort" : [
1601316101191
]
}
]
}
}
},
{
"key" : "AAL2323",
"doc_count" : 9,
"entityHits" : {
"hits" : {
"total" : {
"value" : 9,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "flight_tracks",
"_id" : "n-ng1XQB6yyY-xQxnGSM",
"_score" : null,
"fields" : {
"time_data.@timestamp" : [
"2020-09-28T18:01:41.191Z"
],
"geo.coords.location" : [
"41.6677269525826, -84.71324851736426"
],
"entity_id" : [
"AAL2323"
]
},
"sort" : [
1601316101191
]
}
]
}
}
},
{
"key" : "ABD5250",
"doc_count" : 9,
"entityHits" : {
"hits" : {
"total" : {
"value" : 9,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "flight_tracks",
"_id" : "GOng1XQB6yyY-xQxnGWM",
"_score" : null,
"fields" : {
"time_data.@timestamp" : [
"2020-09-28T18:01:41.192Z"
],
"geo.coords.location" : [
"39.07997465226799, 6.073727197945118"
],
"entity_id" : [
"ABD5250"
]
},
"sort" : [
1601316101192
]
}
]
}
}
}
]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import sampleJsonResponse from './es_sample_response.json';
import sampleJsonResponseWithNesting from './es_sample_response_with_nesting.json';
import { getMovedEntities, transformResults } from '../geo_threshold';
import { OTHER_CATEGORY } from '../es_query_builder';
import { SearchResponse } from 'elasticsearch';
Expand Down Expand Up @@ -51,6 +52,46 @@ describe('geo_threshold', () => {
]);
});

const nestedDateField = 'time_data.@timestamp';
const nestedGeoField = 'geo.coords.location';
it('should correctly transform expected results if fields are nested', async () => {
const transformedResults = transformResults(
(sampleJsonResponseWithNesting as unknown) as SearchResponse<unknown>,
nestedDateField,
nestedGeoField
);
expect(transformedResults).toEqual([
{
dateInShape: '2020-09-28T18:01:41.190Z',
docId: 'N-ng1XQB6yyY-xQxnGSM',
entityName: '936',
location: [-82.8814151789993, 40.62806099653244],
shapeLocationId: '0DrJu3QB6yyY-xQxv6Ip',
},
{
dateInShape: '2020-09-28T18:01:41.191Z',
docId: 'iOng1XQB6yyY-xQxnGSM',
entityName: 'AAL2019',
location: [-82.22068064846098, 39.006176185794175],
shapeLocationId: '0DrJu3QB6yyY-xQxv6Ip',
},
{
dateInShape: '2020-09-28T18:01:41.191Z',
docId: 'n-ng1XQB6yyY-xQxnGSM',
entityName: 'AAL2323',
location: [-84.71324851736426, 41.6677269525826],
shapeLocationId: '0DrJu3QB6yyY-xQxv6Ip',
},
{
dateInShape: '2020-09-28T18:01:41.192Z',
docId: 'GOng1XQB6yyY-xQxnGWM',
entityName: 'ABD5250',
location: [6.073727197945118, 39.07997465226799],
shapeLocationId: '0DrJu3QB6yyY-xQxv6Ip',
},
]);
});

it('should return an empty array if no results', async () => {
const transformedResults = transformResults(undefined, dateField, geoField);
expect(transformedResults).toEqual([]);
Expand Down