text: /*
   * Licensed to Elasticsearch B.V. under one or more contributor
   * license agreements. See the NOTICE file distributed with
   * this work for additional information regarding copyright
   * ownership. Elasticsearch B.V. licenses this file to you under
   * the Apache License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  
  'use strict'
  
  /* eslint camelcase: 0 */
  /* eslint no-unused-vars: 0 */
  
  function buildCount (opts) {
    // eslint-disable-next-line no-unused-vars
    const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts
    /**
     * Perform a [count](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html) request
     *
     * @param {list} index - A comma-separated list of indices to restrict the results
     * @param {list} type - A comma-separated list of types to restrict the results
     * @param {boolean} ignore_unavailable - Whether specified concrete indices should be ignored when unavailable (missing or closed)
     * @param {boolean} ignore_throttled - Whether specified concrete, expanded or aliased indices should be ignored when throttled
     * @param {boolean} allow_no_indices - Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
     * @param {enum} expand_wildcards - Whether to expand wildcard expression to concrete indices that are open, closed or both.
     * @param {number} min_score - Include only documents with a specific `_score` value in the result
     * @param {string} preference - Specify the node or shard the operation should be performed on (default: random)
     * @param {list} routing - A comma-separated list of specific routing values
     * @param {string} q - Query in the Lucene query string syntax
     * @param {string} analyzer - The analyzer to use for the query string
     * @param {boolean} analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false)
     * @param {enum} default_operator - The default operator for query string query (AND or OR)
     * @param {string} df - The field to use as default where no field prefix is given in the query string
     * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
     * @param {number} terminate_after - The maximum count for each shard, upon reaching which the query execution will terminate early
     * @param {object} body - A query to restrict the results specified with the Query DSL (optional)
     */
  
    const acceptedQuerystring = [
      'ignore_unavailable',
      'ignore_throttled',
      'allow_no_indices',
      'expand_wildcards',
      'min_score',
      'preference',
      'routing',
      'q',
      'analyzer',
      'analyze_wildcard',
      'default_operator',
      'df',
      'lenient',
      'terminate_after',
      'pretty',
      'human',
      'error_trace',
      'source',
      'filter_path'
    ]
  
    const snakeCase = {
      ignoreUnavailable: 'ignore_unavailable',
      ignoreThrottled: 'ignore_throttled',
      allowNoIndices: 'allow_no_indices',
      expandWildcards: 'expand_wildcards',
      minScore: 'min_score',
      analyzeWildcard: 'analyze_wildcard',
      defaultOperator: 'default_operator',
      terminateAfter: 'terminate_after',
      errorTrace: 'error_trace',
      filterPath: 'filter_path'
    }
  
    return function count (params, options, callback) {
      options = options || {}
      if (typeof options === 'function') {
        callback = options
        options = {}
      }
      if (typeof params === 'function' || params == null) {
        callback = params
        params = {}
        options = {}
      }
  
      // check required url components
      if (params['type'] != null && (params['index'] == null)) {
        const err = new ConfigurationError('Missing required parameter of the url: index')
        return handleError(err, callback)
      }
  
      // validate headers object
      if (options.headers != null && typeof options.headers !== 'object') {
        const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
        return handleError(err, callback)
      }
  
      var warnings = []
      var { method, body, index, type, ...querystring } = params
      querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings)
  
      if (method == null) {
        method = body == null ? 'GET' : 'POST'
      }
  
      var ignore = options.ignore
      if (typeof ignore === 'number') {
        options.ignore = [ignore]
      }
  
      var path = ''
  
      if ((index) != null && (type) != null) {
        path = '/' + encodeURIComponent(index) + '/' + encodeURIComponent(type) + '/' + '_count'
      } else if ((index) != null) {
        path = '/' + encodeURIComponent(index) + '/' + '_count'
      } else {
        path = '/' + '_count'
      }
  
      // build request object
      const request = {
        method,
        path,
        body: body || '',
        querystring
      }
  
      options.warnings = warnings.length === 0 ? null : warnings
      return makeRequest(request, options, callback)
    }
  }
  
  module.exports = buildCount
  