genkid2020

Untitled

Aug 10th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. 1 файл
  2. const es = require('elasticsearch');
  3. const esClient = new es.Client({
  4. host: 'localhost:9200',
  5. log: 'trace'
  6. });
  7. const search = function search(index, body) {
  8. return esClient.search({index: index, body: body});
  9. };
  10.  
  11. module.exports = search;
  12. 2 файл
  13. let body = {
  14. query: {
  15. match_all:
  16. {output}
  17. }
  18. };
  19. search('SAP', body)
  20. .then(results => {
  21. console.log(`found ${results.hits.total} items in ${results.took}ms`);
  22. console.log(`returned article titles:`);
  23. results.hits.hits.forEach((hit, index) => console.log(`\t${body.from + ++index} - ${hit._source.title}`));
  24. })
  25. .catch(console.error);
Advertisement
Add Comment
Please, Sign In to add comment