<commit_before>var es = require('es')({
  _index: 'campaign-spending',
  server: {
    auth: process.env.ESAUTH || '',
    host: process.env.ESHOST || 'localhost',
    port: process.env.ESPORT || '9200'
  }
});

function error (err, res) {
  console.error(err.stack);
  res.statusCode = 500;
  res.end('{"message": "Internal Error"}');
}

function badRequest (res) {
  console.warn('Warning: Bad Request');
  res.statusCode = 400;
  res.end('{"message": "Bad Request"}');
}

module.exports = function (req, res) {
  var params = req.parsedUrl.query;
  var query = {
    from: params.from,
    facets: {
      name: {terms: {field: "name.raw"}},
      category: {terms: {field: "category.raw"}},
      amount: {
        range: {
          field: 'amount',
          ranges: [
            {to: 100},
            {from: 100, to: 1000},
            {from: 1000, to: 10000},
            {from: 10000, to: 100000},
            {from: 100000}
          ]
        }
      }
    }
  };
  res.setHeader('Content-Type', 'application/json');
  if (params.q) {
    query.query = {<commit_msg>Name facet can now show all council names<commit_after>var es = require('es')({
  _index: 'campaign-spending',
  server: {
    auth: process.env.ESAUTH || '',
    host: process.env.ESHOST || 'localhost',
    port: process.env.ESPORT || '9200'
  }
});

function error (err, res) {
  console.error(err.stack);
  res.statusCode = 500;
  res.end('{"message": "Internal Error"}');
}

function badRequest (res) {
  console.warn('Warning: Bad Request');
  res.statusCode = 400;
  res.end('{"message": "Bad Request"}');
}

module.exports = function (req, res) {
  var params = req.parsedUrl.query;
  var query = {
    from: params.from,
    facets: {
      name: {terms: {field: "name.raw", size: 20}},
      category: {terms: {field: "category.raw"}},
      amount: {
        range: {
          field: 'amount',
          ranges: [
            {to: 100},
            {from: 100, to: 1000},
            {from: 1000, to: 10000},
            {from: 10000, to: 100000},
            {from: 100000}
          ]
        }
      }
    }
  };
  res.setHeader('Content-Type', 'application/json');
  if (params.q) {
    query.query = {
{'fraction_non_alphanumeric': 0.1785063752276867, 'fraction_numerical': 0.042805100182149364, 'mean_word_length': 2.3287878787878786, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '686825', 'n_tokens_mistral': 830, 'n_tokens_neox': 738, 'n_words': 171}