normanjoyner/chef-api

getSearchIndex produces bad request parameters

babysnakes opened this issue · 1 comments

I was trying to figure out why I'm getting all my nodes in return for a query that searches only for ec2 nodes:

chef.getSearchIndex("node", "ec2:*", function(err, data) {
  if (err) return console.log(err);
  // do some stuff
});

I created a simple node server that logs the requested url:

var http = require("http");
var server = http.createServer(function(req, res) {
  debugger;
  console.log(req.url);
  // console.log(req.headers);
  res.writeHead(404, {'Content-Type': 'application/json'});
  res.end("[]");
}).listen(3000);

Now when running knife search node "ec2:*" -s "http://localhost:3000" the following is printed:

/search/node?q=ec2%253A*&sort=&start=0&rows=1000

but when running the getSearchIndex as shown above I get the following:

/search/node?0=e&1=c&2=2&3=%3A&4=*&bold=%1B%5B1mec2%3A*%1B%5B... (it continues a couple of hundred characters longer).

Thanks in advance.

Oh, by looking at previous issues I saw that you need a query object and not a query string. I'm closing this and I'll later add a PR for adding search example to the README.md in the methods directory.