text: 'use strict';
  
  exports.__esModule = true;
  exports.getCompositeAggsQuery = exports.getAggsQuery = undefined;
  
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  
  var _helper = require('@appbaseio/reactivecore/lib/utils/helper');
  
  var getAggsQuery = function getAggsQuery(query, props) {
  	var _clonedQuery$aggs;
  
  	var clonedQuery = _extends({}, query);
  	var dataField = props.dataField,
  	    size = props.size,
  	    sortBy = props.sortBy,
  	    showMissing = props.showMissing,
  	    missingLabel = props.missingLabel;
  
  	clonedQuery.size = 0;
  	clonedQuery.aggs = (_clonedQuery$aggs = {}, _clonedQuery$aggs[dataField] = {
  		terms: _extends({
  			field: dataField,
  			size: size,
  			order: (0, _helper.getAggsOrder)(sortBy || 'count')
  		}, showMissing ? { missing: missingLabel } : {})
  	}, _clonedQuery$aggs);
  
  	if (props.nestedField) {
  		clonedQuery.aggs = {
  			reactivesearch_nested: {
  				nested: {
  					path: props.nestedField
  				},
  				aggs: clonedQuery.aggs
  			}
  		};
  	}
  
  	return clonedQuery;
  };
  
  var getCompositeAggsQuery = function getCompositeAggsQuery(query, props, after) {
  	var _ref, _clonedQuery$aggs2;
  
  	var clonedQuery = _extends({}, query);
  	// missing label not available in composite aggs
  	var dataField = props.dataField,
  	    size = props.size,
  	    sortBy = props.sortBy,
  	    showMissing = props.showMissing;
  
  	// composite aggs only allows asc and desc
  
  	var order = sortBy === 'count' ? {} : { order: sortBy };
  
  	clonedQuery.aggs = (_clonedQuery$aggs2 = {}, _clonedQuery$aggs2[dataField] = {
  		composite: _extends({
  			sources: [(_ref = {}, _ref[dataField] = {
  				terms: _extends({
  					field: dataField
  				}, order, showMissing ? { missing_bucket: true } : {})
  			}, _ref)],
  			size: size
  		}, after)
  	}, _clonedQuery$aggs2);
  
  	if (props.nestedField) {
  		clonedQuery.aggs = {
  			reactivesearch_nested: {
  				nested: {
  					path: props.nestedField
  				},
  				aggs: clonedQuery.aggs
  			}
  		};
  	}
  
  	return clonedQuery;
  };
  
  exports.getAggsQuery = getAggsQuery;
  exports.getCompositeAggsQuery = getCompositeAggsQuery;