Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function createIndex(product) {
  2.         client.create({
  3.             index: 'test-products',
  4.             type: 'product',
  5.             id: product._id.toHexString(),
  6.             body: {
  7.                 SKU: product.SKU,
  8.                 Name: product.Name,
  9.                 Cost: product.Cost,
  10.                 supplierId: product.supplierId.toHexString()
  11.             }
  12.         }, function (error, response) {
  13.             console.log('ERROR',error);
  14.             console.log('RESPONSE',response);
  15.         });
  16.     }
  17.  
  18.     Product.find({},{},function(err,results){
  19.         for (var i = 0; i < results.length; i++) {
  20.             createIndex(results[i]);
  21.         };
  22.     });
  23. ////////////////////////////////////////////////////////////
  24.  
  25. client.search({
  26.     index: 'test-products',
  27.     type: 'product',
  28.     body: {
  29.         "query": {
  30.             "filtered": {
  31.                 "query": { "match": { "_all": 'W-814' }},
  32.                 "filter": {
  33.                     "bool": {
  34.                         "must": { "term": { "supplierId": '53a8a7299d3d147c39bd6ac9' }},
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }).then(function (body) {
  41.     res.send(body);
  42. }, function (error) {
  43.     res.send(error);
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement