Skip to content

Commit

Permalink
[#55] feat - elastic search
Browse files Browse the repository at this point in the history
  • Loading branch information
dbckdgjs369 committed Feb 2, 2021
1 parent 331c6ea commit cece143
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions routes/search.js
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions routes/server.client.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit cece143

Please sign in to comment.