genkid2020

Untitled

Aug 11th, 2020
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. const es = require('elasticsearch');
  2. const search = (search_keyword,data) => {
  3. const esClient = new es.Client({
  4. host: 'localhost:9200',
  5. log: 'trace'
  6. });
  7.  
  8. esClient.indices.create({
  9. index: 'test',
  10. body: data,
  11. });
  12. esClient.search({
  13. index: 'test',
  14. body: {
  15. query: {
  16. multi_match : {
  17. query: search_keyword,
  18. fields: [ "id", "name", "snippet" ],
  19. operator:"or"
  20. }
  21. }
  22. }
  23. })
  24. };
  25. module.exports=search;
  26.  
Advertisement
Add Comment
Please, Sign In to add comment