Hi, everyone. I am new to elasticsearch and I really need your help.
i have construced a react app that simulates a search engine. My app uses node.js and express. I have built both a server and a client. In the app I retrieve data directly from an index, I create a documentObject and then I ahve a query in order that the user gets the desired results. The app and the whole implementation in my local pc works like a charm. But when I deploy my app in a VM online and do all the respective changes concerning the server IP and the app always return as results an empty array. No errors occur in network or response neteir in the server or th client.
The code that I use to retrieve the data, and works perfect in local implementation, is :
const express = require("express");
const router = express.Router();
const axios = require("axios");
const client = require("../elasticsearch/client");
require("log-timestamp");
router.get("/documents", async function (req, res) {
console.log("Loading Application...");
res.json("Running Application...");
const indexData = async () => {
try {
console.log("Retrieving data from the Elastic Search Index");
const data = await client.search({
index: "diavgeia_data_and_entities_index_2",
// index: "diavgeia_fields_and_entities_out3",
size: 10000,
});
console.log(data);
const results = data.hits.hits.map((hit) => hit._source);
console.log("Data retrieved!");
console.log("Indexing data...");
await Promise.all(
results.map(async (result) => {
const documentObject = {
ada: result.ada,
AFM: result.AFM,
AMKA: result.AMKA,
CARDINAL: result.CARDINAL,
DATE: result.DATE,
DECISION: result.DECISION,
decisionTypeLabel: result.decisionTypeLabel,
decisionTypeUid: result.decisionTypeUid,
documentUrl: result.documentUrl,
DOMAIN: result.DOMAIN,
EMAIL: result.EMAIL,
EVENT: result.EVENT,
FAC: result.FAC,
GPE: result.GPE,
HASHTAG: result.HASHTAG,
IBAN: result.IBAN,
issueDate: result.issueDate,
LANGUAGE: result.LANGUAGE,
LAW: result.LAW,
LOC: result.LOC,
MENTION: result.MENTION,
MONEY: result.MONEY,
NORP: result.NORP,
ORIGINAL: result.ORIGINAL,
ORG: result.ORG,
organizationLabel: result.organizationLabel,
organizationUid: result.organizationUid,
PERCENT: result.PERCENT,
PERSON: result.PERSON,
PHONE: result.PHONE,
PRODUCT: result.PRODUCT,
protocolNumber: result.protocolNumber,
QUANTITY: result.QUANTITY,
subject: result.subject,
submissionTimestamp: result.submissionTimestamp,
TIME: result.TIME,
URL: result.URL,
WORK_OF_ART: result.WORK_OF_ART,
};
await client.index({
index: "diavgeia_data_and_entities_index_2",
// index: "diavgeia_fields_and_entities_out3",
id: result.id,
body: documentObject,
// pipeline: "diavgeia_data_and_entities_index-pipeline",
});
})
);
console.log("Data has been indexed successfully!");
} catch (err) {
console.log(err);
}
console.log("Preparing for the next round of indexing...");
};
indexData();
});
module.exports = router;
The commented out index is the one of the server. Also the query that I am running in the server is:
const { Client } = require("@elastic/elasticsearch");
const express = require("express");
const client = require("./elasticsearch/client");
const cors = require("cors");
const app = express();
const data = require("./data_management/retrieve_and_ingest_data_diavgeia");
app.use("/ingest_data", data);
app.use(cors());
app.get("/results", (req, res) => {
const criteria = [
{
range: {
"@timestamp": {
gte: `now-${req.query.dateRange}d/d`,
lt: "now/d",
},
},
},
];
if (req.query.ada) {
criteria.push({
match_phrase: { ada: req.query.ada },
});
}
if (req.query.AFM) {
criteria.push({
match_phrase: { AFM: req.query.AFM },
});
}
if (req.query.AMKA) {
criteria.push({
match_phrase: { AMKA: req.query.AMKA },
});
}
if (req.query.decisionTypeUid) {
criteria.push({
match_phrase: { decisionTypeUid: req.query.decisionTypeUid },
});
}
if (req.query.EMAIL) {
const email = req.query.EMAIL;
criteria.push({
wildcard: { EMAIL: `*${email}*` },
});
}
if (req.query.LAW) {
criteria.push({
match_phrase: { LAW: req.query.LAW },
});
}
if (req.query.PERSON) {
criteria.push({
match_phrase: { PERSON: req.query.PERSON },
});
}
if (req.query.PHONE) {
criteria.push({
match_phrase: { PHONE: req.query.PHONE },
});
}
if (req.query.protocolNumber) {
const protocolNumberv = req.query.protocolNumber;
criteria.push({
wildcard: { protocolNumber: `*${protocolNumberv}*` },
});
}
async function sendESRequest() {
try {
const body = await client.search({
index: "diavgeia_data_and_entities_index_2",
// index: "diavgeia_fields_and_entities_out3",
body: {
size: 10000,
query: {
bool: {
must: criteria,
},
},
},
});
res.json(body.hits.hits);
} catch (error) {
console.error("Elasticsearch search error:", error);
res.status(500).json({ error: "Internal server error" });
}
}
sendESRequest();
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => console.group(`Server started on ${PORT}`));
All respective changes on the VM server are made. Any ideas why is this possibly happening? Thank you in advance.