Hi this is my first question in this forum. I am new to elastic search.
I have an express.js project. ORM is sequlize.js
I have three tables.
-
Category
-
Item
-
City
I have search bar in mobile app where users can search category, item or a city.
So what I did in my category.controller.js file
async function create(req, res, next) {
const transaction = await db.sequelize.transaction();
try {
const data = await db[model_name].create(req.body, {
transaction
});
await client.create({
index: 'live_search_index',
type: 'default',
id: `cat ${data.dataValues.id}`,
body: {
title: `${req.body.name}`,
my_type: `${req.body.my_type}`,
my_id: data.dataValues.id,
my_status: true
}
});
await transaction.commit();
res.sendStatus(200);
} catch (error) {
console.log("ERR", error);
await transaction.rollback();
res.sendStatus(500);
}
}
But I have 3 controllers and each controller I need to alter 3 functions (create, update, enableDisable). So a lot of work and painful.
There might be a smart way to do this.
You install a plugin and all the CRUD operations of a certain table will be automatically sync to elastic search so that no pain.
Is there a way to do so?
or else do I need to continue in this way?
Any help!
Thanks in advanced.