diff --git a/app.js b/app.js index ae47402..78f2d36 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,7 @@ var projectRouter = require("./routes/project"); var userRouter = require("./routes/user"); var categoryRouter = require("./routes/category"); var authRouter = require("./routes/auth"); +var searchRouter= require("./routes/search"); let corsOptions = { origin: "http://localhost:3000", @@ -46,6 +47,7 @@ app.use("/api/user", userRouter); app.use("/api/category", categoryRouter); app.use("/auth", authRouter); app.use('/uploads', express.static('uploads')); +app.use('/api/search', searchRouter); // catch 404 and forward to error handler app.use(function (req, res, next) { diff --git a/package.json b/package.json index 1eecc16..129d72a 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "cookie-parser": "~1.4.4", "cors": "^2.8.5", "debug": "~2.6.9", + "elasticsearch": "^16.7.2", "express": "~4.16.1", "express-session": "^1.17.1", "http-errors": "~1.6.3", diff --git a/routes/search.js b/routes/search.js new file mode 100644 index 0000000..747ccc1 --- /dev/null +++ b/routes/search.js @@ -0,0 +1,13 @@ +var express = require("express"); +var router = express.Router(); +const client = require('./server.client'); +// const { getCategory } = require("../db/category"); + +//모든 카테고리 조회 +router.post("/", async function (req, res, next) { + //console.log(req.body); +// console.log(res.json(client.search({index:"title",body:req.body}))) + return client.search({index: 'title', body: req.body}) +}); + +module.exports = router; diff --git a/routes/server.client.js b/routes/server.client.js new file mode 100644 index 0000000..c470bb4 --- /dev/null +++ b/routes/server.client.js @@ -0,0 +1,11 @@ +const ElasticSearch = require('elasticsearch'); + +/** + * *** ElasticSearch *** client + * @type {Client} + */ +const client = new ElasticSearch.Client({ + hosts: ['http://127.0.0.1:9200'] +}); + +module.exports = client; \ No newline at end of file