forked from nasa-gcn/gcn.nasa.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox-search.js
29 lines (28 loc) · 918 Bytes
/
sandbox-search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*!
* Copyright © 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import { readFile } from 'fs/promises'
import groupBy from 'lodash/groupBy.js'
export default async function () {
const text = await readFile('sandbox-seed.json', { encoding: 'utf-8' })
const { circulars, synonyms } = JSON.parse(text)
const groups = Object.entries(groupBy(synonyms, 'synonymId')).flatMap(
([synonymId, values]) => [
{ synonymId, eventIds: values.map(({ eventId }) => eventId) },
]
)
return [
...circulars.flatMap((item) => [
{ index: { _index: 'circulars', _id: item.circularId.toString() } },
item,
]),
...groups.flatMap((item) => [
{ index: { _index: 'synonym-groups', _id: item.synonymId.toString() } },
item,
]),
]
}