Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const es = require('elasticsearch');
- const search = async (search_keyword, data) => {
- const esClient = new es.Client({
- host: 'localhost:9200',
- log: 'trace'
- });
- await esClient.indices.create({
- index: 'test',
- body: data,
- });
- await esClient.search({
- index: 'test',
- body: {
- query: {
- multi_match: {
- query: search_keyword,
- fields: ["id", "name", "snippet"],
- operator: "or"
- }
- }
- }
- })
- };
- module.exports=search;
- в сервере
- const express = require("express");
- const app = express();
- const parser = require('./parser/parser');
- const routes=require('./routes/routes');
- const search=require('./elasticsearch/search')
- ;(async () => {
- const result = await parser();
- result.forEach(item => {
- const data = JSON.parse(item.data);
- const output = data.items.map(({id, name, snippet}) => ({
- id,
- name,
- snippet
- }));
- //console.log(output)
- search("JS",output);
- });
- })();
- routes(app);
- const server = app.listen(3001, () => {
- console.log("listening on port %s...", server.address().port);
- });
Advertisement
Add Comment
Please, Sign In to add comment