sepia-search-motore-di-rice.../server/helpers/elastic-search.ts

28 lines
556 B
TypeScript

import { Client } from '@elastic/elasticsearch'
import { CONFIG } from '../initializers/constants'
const client = new Client({ node: CONFIG.ELASTIC_SEARCH.HOSTNAME + ':' + CONFIG.ELASTIC_SEARCH.PORT })
function indexVideo (body: any) {
return client.index({
index: CONFIG.ELASTIC_SEARCH.INDEXES.VIDEOS,
body
})
}
async function queryVideos (query: any) {
const res = await client.search({
index: CONFIG.ELASTIC_SEARCH.INDEXES.VIDEOS,
body: {
query
}
})
return res.hits.hits
}
export {
indexVideo,
queryVideos
}