2021-07-15 14:59:11 +00:00
|
|
|
export async function search(client, index: string, query: string): Promise<object> {
|
|
|
|
|
const result = await client.search({
|
|
|
|
|
index,
|
2021-09-21 13:48:28 +00:00
|
|
|
body: JSON.parse(query),
|
|
|
|
|
});
|
2021-07-15 14:59:11 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function indexDocument(client, index: string, body: string): Promise<object> {
|
|
|
|
|
const result = await client.index({
|
|
|
|
|
index,
|
2021-09-21 13:48:28 +00:00
|
|
|
body: JSON.parse(body),
|
|
|
|
|
});
|
2021-07-15 14:59:11 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getDocument(client, index: string, id: string): Promise<object> {
|
|
|
|
|
const result = await client.get({ index, id });
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateDocument(client, index: string, id: string, body: string): Promise<object> {
|
|
|
|
|
const result = await client.update({
|
|
|
|
|
index,
|
|
|
|
|
id,
|
2021-09-21 13:48:28 +00:00
|
|
|
body: JSON.parse(body),
|
|
|
|
|
});
|
2021-07-15 14:59:11 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|