├── README.md ├── index.js ├── lib └── elsQuery.js ├── package.json └── test.js /README.md: -------------------------------------------------------------------------------- 1 | # elasticsearch-query 2 | 3 | elasticsearch-query easily generate complex elasticsearch queries (last version for ELS 5.X) 4 | 5 | ## Installation 6 | npm install elasticsearch-query 7 | 8 | 9 | ## Simple queries : mustQuery, orQuery, mustNotQuery 10 | 11 | var elsQuery = require('elasticsearch-query'); 12 | var elsGeneratorQueries = new elsQuery(); 13 | 14 | var type = null; 15 | 16 | var mustQuery = { 17 | 'createdBy': 'kimchy' 18 | }; 19 | 20 | /* 21 | ** method@generate(type, query, queryAggregations, match_type, callback); 22 | ** 23 | ** type (string) type on your elasticsearch index (not necessary could be null) 24 | ** query (object) that you want to transform 25 | ** queryAggregations (object) elasticsearch query if you want an aggregation more specific 26 | ** match_type (object) you can use {term: true}, or {match: true}, {match_phrase_prefix: true}, ... 27 | ** callback (function) return err & queryELS 28 | */ 29 | elsGeneratorQueries.generate(type, mustQuery, null, {term: true}, function(err, queryELS) { 30 | console.log('mustQuery ->', JSON.stringify(queryELS)); 31 | }); 32 | 33 | ==> queryELS 34 | { 35 | "query": { 36 | "bool":{ 37 | "must":[ 38 | { 39 | "term":{ 40 | "createdBy":"kimchy" 41 | } 42 | } 43 | ], 44 | "must_not":[], 45 | "should":[], 46 | "filter":[] 47 | } 48 | } 49 | } 50 | <== 51 | 52 | // I want documents createdBy kimchy or postedBy boubaks 53 | var orQuery = { 54 | '|createdBy': 'kimchy', 55 | '|postedBy': 'boubaks' 56 | }; 57 | elsGeneratorQueries.generate(type, orQuery, null, {term: true}, function(err, queryELS) { 58 | console.log('orQuery ->', JSON.stringify(queryELS)); 59 | }); 60 | 61 | 62 | // I want documents not createdBy kimchy & not postedBy boubaks 63 | var mustNotQuery = { 64 | '!createdBy': 'kimchy', 65 | '!postedBy': 'boubaks' 66 | } 67 | elsGeneratorQueries.generate(type, mustNotQuery, null, {term: true}, function(err, queryELS) { 68 | console.log('mustNotQuery ->', JSON.stringify(queryELS)); 69 | }); 70 | 71 | ## Range queries : $gt, $gte, $in, $lt, $lte, $ne & $nin 72 | 73 | // I want documents where "age" is between 18 and 60 both included 74 | var rangeQuery = { 75 | '$lte': { 'age': 60 }, 76 | '$gte': { 'age': 18 } 77 | }; 78 | 79 | elsGeneratorQueries.generate(type, rangeQuery, null, {term: true}, function(err, queryELS) { 80 | console.log('rangeQuery ->', JSON.stringify(queryELS)); 81 | }); 82 | ==> queryELS 83 | { 84 | "query":{ 85 | "bool":{ 86 | "must":[ 87 | { 88 | "range":{ 89 | "age":{ 90 | "lte":60, 91 | "gte":18 92 | } 93 | } 94 | } 95 | ], 96 | "must_not":[], 97 | "should":[], 98 | "filter": [] 99 | } 100 | } 101 | <== 102 | 103 | ## Complexes queries ($facet, $exist, $not_exist) 104 | 105 | // I want the username aggregation and count between VERIFIED people where the field AGE exist and between 18-60 years old, not include boubaks 106 | var complexQuery = { 107 | 'verified': true, 108 | '$exist': 'age', 109 | '$lte': { 'age': 60 }, 110 | '$gte': { 'age': 18 }, 111 | '!username': 'boubaks', 112 | '$facet': 'username', 113 | '$count': true 114 | }; 115 | 116 | elsGeneratorQueries.generate(type, complexQuery, null, {term: true}, function(err, queryELS) { 117 | console.log('complexQuery ->', JSON.stringify(queryELS)); 118 | }); 119 | 120 | ==> queryELS 121 | { 122 | "query":{ 123 | "bool":{ 124 | "must":[ 125 | { 126 | "term":{ 127 | "verified":true 128 | } 129 | }, 130 | { 131 | "range":{ 132 | "age":{ 133 | "lte":60, 134 | "gte":18 135 | } 136 | } 137 | }, 138 | { 139 | "exists":{ 140 | "field":"age" 141 | } 142 | } 143 | ], 144 | "must_not":[ 145 | { 146 | "term":{ 147 | "username":"boubaks" 148 | } 149 | } 150 | ], 151 | "should":[], 152 | "filter": [] 153 | } 154 | }, 155 | "aggregations":{ 156 | "aggs":{ 157 | "terms":{ 158 | "field":"username", 159 | "size":10 160 | } 161 | } 162 | } 163 | } 164 | <== 165 | 166 | ## elsQuery object 167 | You can add an handle function to a specific field setted 168 | 169 | // addHandle(param, defaultValue, fcn); 170 | // deleteHandle(index[, all (boolean)]); 171 | // getHandles(); // console.log by default (will be removed) 172 | 173 | /* 174 | ** @query: {$test: "elasticsearch"} 175 | ** @queryELS: the query generate for elasticsearch 176 | ** callback: function(err, queryELS) 177 | */ 178 | var handleTest = function (query, queryELS, callback) { 179 | var error = null; 180 | if (query.$test) { 181 | // Do your stuff 182 | } 183 | callback(error, queryELS); 184 | }; 185 | 186 | elsQueryGenerator.addHandle('$test', null, handleTest); 187 | ## Notes 188 | If you want to do specific action or normal query on $page, $limit, $sort, $skip, $handle you have to add handle function 189 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require(__dirname + '/lib/elsQuery').elsQuery; 2 | -------------------------------------------------------------------------------- /lib/elsQuery.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /////////////////////////////////////////////////////////////////////////////// 3 | // elsQuery object // 4 | /////////////////////////////////////////////////////////////////////////////// 5 | var me = undefined; 6 | exports.elsQuery = function(callback) { 7 | this.query = {}; 8 | this.options = {}; 9 | this.mappingExecution = [ 10 | {param: '$page', defaultValue: 1, fcn: handlePage}, 11 | {param: '$limit', defaultValue: 10, fcn: handleLimit}, 12 | {param: '$sort', defaultValue: null, fcn: handleSort}, 13 | {param: '$skip', defaultValue: 0, fcn: handleSkip}, 14 | {param: '$handle', defaultValue: null, fcn: handleQuery}, 15 | {param: '$facet', defaultValue: null, fcn: handleFacet}, 16 | {param: '$count', defaultValue: false, fcn: handleCount}, 17 | {param: ['$gt', '$gte', '$in', '$lt', '$lte', '$ne', '$nin'], defaultValue: null, fcn: handleComparison}, 18 | {param: ['$exist', '$not_exist'], defaultValue: null, fcn: handleExists} 19 | ]; 20 | me = this; 21 | if (callback && typeof(callback) === 'function') { 22 | callback(this); 23 | } else { 24 | return (this); 25 | } 26 | } 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | // Private(s) function(s) // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | exports.elsQuery.prototype.isParam = function(param) { 32 | var iterator = 0; 33 | 34 | for (iterator in me.mappingExecution) { 35 | if ((typeof(me.mappingExecution[iterator].param) == 'object' && me.mappingExecution[iterator].param.indexOf(param) > -1) || 36 | me.mappingExecution[iterator].param == param) 37 | return (true); 38 | } 39 | return (false); 40 | } 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | // Publics functions // 44 | // // 45 | // * generate a query for elasticsearch from a simple query // 46 | // * generate use set the elasticquery and get it directly // 47 | /////////////////////////////////////////////////////////////////////////////// 48 | exports.elsQuery.prototype.generate = function(type, query, aggregations, options, callback) { 49 | var iterator = 0; 50 | 51 | if (query && typeof(query) === 'object' && !(query instanceof Array)) { 52 | for (iterator in me.mappingExecution) { 53 | this[me.mappingExecution[iterator].param] = query[me.mappingExecution[iterator].param] ? 54 | query[me.mappingExecution[iterator].param] : me.mappingExecution[iterator].defaultValue; 55 | } 56 | var queryELS = {} 57 | this.set(type, query, aggregations, options, function(err) { 58 | queryELS = me.get(); 59 | if (callback && typeof(callback) === 'function') { 60 | callback(err, queryELS); 61 | } 62 | }); 63 | return (queryELS); 64 | } else { 65 | if (callback && typeof(callback) === 'function') { 66 | callback(null, null); 67 | } else { 68 | return (null); 69 | } 70 | } 71 | } 72 | 73 | function processExec(step, query, queryELS, callback) { 74 | me.mappingExecution[step].fcn(query, queryELS, function(err, results) { 75 | // if (me.mappingExecution[step]) { console.log('execution', me.mappingExecution[step].param); } 76 | queryELS = results; 77 | ++step; 78 | if (err) { 79 | callback(err, queryELS); 80 | } else if (step < me.mappingExecution.length) { 81 | processExec(step, query, queryELS, callback); 82 | } else { 83 | callback(err, queryELS); 84 | } 85 | }); 86 | } 87 | 88 | /* 89 | ** set the elasticquery 90 | */ 91 | exports.elsQuery.prototype.set = function(type, query, aggregations, options, callback) { 92 | var iterator = 0; 93 | var term = {}; 94 | var queryELS = { 95 | "query": { 96 | "bool": { 97 | "must": [], 98 | "must_not": [], 99 | "should": [], 100 | "filter": [] 101 | } 102 | } 103 | }; 104 | if (type) { 105 | queryELS.query.bool.filter.push({ 106 | "term": { 107 | "_type": type 108 | } 109 | }); 110 | } 111 | me.options = options ? options : null; 112 | if (aggregations) { 113 | queryELS.aggregations = aggregations; 114 | } 115 | processExec(iterator, query, queryELS, function(err, results) { 116 | me.query = results; 117 | callback(err); 118 | }); 119 | } 120 | 121 | /* 122 | ** return the elasticquery 123 | */ 124 | exports.elsQuery.prototype.get = function() { 125 | return (this.query); 126 | } 127 | 128 | /* 129 | ** add a function passed in parameters to the generate function flow 130 | */ 131 | exports.elsQuery.prototype.addHandle = function(param, defaultValue, fcn) { 132 | me.mappingExecution.unshift({param: param, defaultValue: defaultValue, fcn: fcn}); 133 | } 134 | 135 | /* 136 | ** delete a handle 137 | */ 138 | exports.elsQuery.prototype.deleteHandle = function(index, all) { 139 | if (all == true) { 140 | var length = me.mappingExecution.length; 141 | me.mappingExecution.splice(0, length); 142 | } else { 143 | me.mappingExecution.splice(index, 1); 144 | } 145 | } 146 | 147 | /* 148 | ** get the handles parameters 149 | */ 150 | exports.elsQuery.prototype.getHandles = function() { 151 | var handles = this.mappingExecution; 152 | console.log(handles); 153 | return (handles); 154 | } 155 | 156 | /////////////////////////////////////////////////////////////////////////////// 157 | // Handles functions // 158 | /////////////////////////////////////////////////////////////////////////////// 159 | function handleExists(query, queryELS, callback) { 160 | if (query.$exist) { 161 | var must = queryELS.query.bool.must ? queryELS.query.bool.must : new Array(); 162 | must.push({"exists" : { "field" : query.$exist }}); 163 | } 164 | if (query.$not_exist) { 165 | var must_not = queryELS.query.bool.must_not ? queryELS.query.bool.must_not : new Array(); 166 | must_not.push({"exists" : { "field" : query.$not_exist }}); 167 | } 168 | callback(null, queryELS); 169 | } 170 | 171 | function handleComparison(query, queryELS, callback) { 172 | var param = null; 173 | var newParam = null; 174 | var paramsArray = []; 175 | var ComparisonParams = ['$gt', '$gte', '$in', '$lt', '$lte', '$ne', '$nin'] 176 | for (param in query) { 177 | if (ComparisonParams.indexOf(param) >= 0) { 178 | var tmpObj = {}; 179 | newParam = param.slice(1); 180 | tmpObj[newParam] = query[param]; 181 | paramsArray.push(tmpObj); 182 | } 183 | } 184 | if (paramsArray.length <= 0) { 185 | callback(null, queryELS); 186 | } else { 187 | var range = []; 188 | var iterator = 0; 189 | var actionField = null; 190 | var termField = null; 191 | var filter = queryELS.query.bool.filter ? queryELS.query.bool.filter : new Array(); 192 | for (iterator in paramsArray) { 193 | for (actionField in paramsArray[iterator]) { 194 | for (termField in paramsArray[iterator][actionField]) { 195 | range[termField] = range[termField] ? range[termField] : {}; 196 | range[termField][actionField] = paramsArray[iterator][actionField][termField]; 197 | } 198 | } 199 | } 200 | for (var field in range) { 201 | var rangeELS = { 202 | range: {} 203 | }; 204 | rangeELS.range[field] = range[field]; 205 | filter.push(rangeELS); 206 | } 207 | // filter.push(range); 208 | callback(null, queryELS); 209 | } 210 | } 211 | 212 | function handleLimit(query, queryELS, callback) { 213 | callback(null, queryELS); 214 | } 215 | 216 | function handleFacet(query, queryELS, callback) { 217 | if (query.$facet) { 218 | var limit = query.$limit ? parseInt(query.$limit) : 10; 219 | var page = query.$page ? parseInt(query.$page) : 1; 220 | var size = parseInt(limit * page); 221 | var aggregations = { 222 | "aggs": { 223 | "terms": { 224 | "field": query.$facet, 225 | "size": size 226 | } 227 | } 228 | }; 229 | if (query.$count && query.$count == 'true') { 230 | var count = { 231 | "cardinality" : { 232 | "field" : query.$facet 233 | } 234 | }; 235 | aggregations.count = count; 236 | } 237 | queryELS.aggregations = aggregations; 238 | } 239 | callback(null, queryELS); 240 | } 241 | 242 | function handleSort(query, queryELS, callback) { 243 | var sortQuery = query['$sort'] ? query['$sort'] : null; 244 | if (typeof sortQuery === 'string') { 245 | try { 246 | sortQuery = JSON.parse(query['$sort']); 247 | console.log(sortQuery); 248 | } catch (e) { 249 | console.log('e', e); 250 | sortQuery = null; 251 | } 252 | } 253 | if (sortQuery) { 254 | for (var value in sortQuery) { 255 | if (sortQuery[value] == 0) { 256 | delete (sortQuery[value]); 257 | } else if (sortQuery[value] > 0) { 258 | // sortQuery[value] = {"order": "asc", "ignore_unmapped": true}; 259 | sortQuery[value] = {"order": "asc"}; 260 | } else { 261 | // sortQuery[value] = {"order": "desc", "ignore_unmapped": true}; 262 | sortQuery[value] = {"order": "desc"}; 263 | } 264 | } 265 | queryELS.sort = [sortQuery]; 266 | } 267 | callback(null, queryELS); 268 | } 269 | 270 | function handleSkip(query, queryELS, callback) { 271 | callback(null, queryELS); 272 | } 273 | 274 | function handlePage(query, queryELS, callback) { 275 | callback(null, queryELS); 276 | } 277 | 278 | function handleCount(query, queryELS, callback) { 279 | callback(null, queryELS); 280 | } 281 | 282 | function _manageFields(field) { 283 | var value = field; 284 | var mapping = { 285 | 'true': true, 286 | 'false': false 287 | }; 288 | if (mapping[field] !== undefined) { 289 | value = mapping[field]; 290 | } 291 | if (typeof(value) === 'string') { 292 | value = value.toLowerCase(); 293 | } 294 | return (value); 295 | } 296 | 297 | function handleBooleanArray(queryELS, param, callback) { 298 | var array = []; 299 | var must = queryELS.query.bool.must ? queryELS.query.bool.must : new Array(); 300 | var must_not = queryELS.query.bool.must_not ? queryELS.query.bool.must_not : new Array(); 301 | var should = queryELS.query.bool.should ? queryELS.query.bool.should : new Array(); 302 | 303 | if (param && param[0] === '!') { 304 | array = must_not; 305 | param = param.slice(1); 306 | } else if (param && param[0] === '|') { 307 | array = should; 308 | param = param.slice(1); 309 | } else { 310 | array = must; 311 | } 312 | callback(array, param); 313 | } 314 | 315 | function handleQuery(query, queryELS, callback) { 316 | var param = null; 317 | var field = null; 318 | var queryDSL = 'term'; 319 | 320 | for (param in query) { 321 | if (me.isParam(param) === false) { 322 | var term = {}; 323 | var originalParam = param; 324 | handleBooleanArray(queryELS, param, function(array, param) { 325 | term[param] = _manageFields(query[originalParam]); 326 | if (me.options) { 327 | for (field in me.options) { 328 | if (me.options[field] === true) { 329 | queryDSL = field; 330 | } 331 | } 332 | } if (queryDSL === 'term') { 333 | if (term && term[param] && Array.isArray(term[param]) === true) { 334 | array.push({'terms': term}); 335 | } else { 336 | array.push({'term': term}); 337 | } 338 | } else if (queryDSL === 'query_string') { 339 | var queryMatch = {} 340 | queryMatch[queryDSL] = { 341 | default_field: param, 342 | query: term[param] 343 | } 344 | array.push(queryMatch) 345 | } else { 346 | // var queryMatch = {'query': {}}; 347 | // queryMatch.query[queryDSL] = term; 348 | var queryMatch = {}; 349 | queryMatch[queryDSL] = term; 350 | array.push(queryMatch); 351 | } 352 | }); 353 | } 354 | } 355 | callback(null, queryELS); 356 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elasticsearch-query", 3 | "version": "1.0.6", 4 | "description": "elasticsearch-query generate queries for elasticsearch by simplify params", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node test.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/boubaks/elasticsearch-query" 12 | }, 13 | "keywords": [ 14 | "elasticsearch" 15 | ], 16 | "author": "boubaks", 17 | "license": "ISC", 18 | "bugs": { 19 | "url": "https://github.com/boubaks/elasticsearch-query/issues" 20 | }, 21 | "homepage": "https://github.com/boubaks/elasticsearch-query" 22 | } 23 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var elsQuery = require(__dirname + '/index'); 2 | var elsGeneratorQueries = new elsQuery(); 3 | 4 | var type = null; 5 | 6 | var query = { 7 | 'createdBy': 'kimchy', 8 | '!product': 'elastic', 9 | '|deleted': 'true', 10 | '$exist': 'age', 11 | '$not_exist': 'name', 12 | '$lte': { 'age': 40 }, 13 | '$gte': { 'age': 30 } 14 | }; 15 | 16 | var simpleQuerySameField = { 17 | 'createdBy': ['kimchy', 'boubaks'] 18 | }; 19 | 20 | var simpleQuery = { 21 | 'createdBy': 'kimchy' 22 | }; 23 | 24 | var rangeQuery = { 25 | '$lte': { 'age': 60 }, 26 | '$gte': { 'age': 18 } 27 | }; 28 | 29 | var orQuery = { 30 | '|createdBy': 'kimchy', 31 | '|postedBy': 'boubaks' 32 | }; 33 | 34 | var notQuery = { 35 | '!createdBy': 'kimchy', 36 | '!postedBy': 'boubaks' 37 | } 38 | 39 | // I want the username aggregation and count between VERIFIED people where the field AGE exist and between 18-60 years old, not include kimchy 40 | var complexQuery = { 41 | 'verified': true, 42 | '$exist': 'age', 43 | '$lte': { 'age': 60 }, 44 | '$gte': { 'age': 18 }, 45 | '$sort': { 'timestamp': -1 }, 46 | '!username': 'kimchy', 47 | '$facet': 'username', 48 | '$count': true 49 | }; 50 | 51 | var multipleRange = { 52 | '$lte': { 'age': 60, 'date': 100060 }, 53 | '$gte': { 'age': 18,'date': 200000 } 54 | }; 55 | 56 | var emptyQuery = {}; 57 | 58 | elsGeneratorQueries.generate(); 59 | 60 | elsGeneratorQueries.generate(type, 'string', null, {term: true}, function(err, queryELS) { 61 | console.log('string error -> ', JSON.stringify(queryELS)); 62 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 63 | }); 64 | 65 | elsGeneratorQueries.generate(type, ['array'], null, {term: true}, function(err, queryELS) { 66 | console.log('array error ->', JSON.stringify(queryELS)); 67 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 68 | }); 69 | 70 | elsGeneratorQueries.generate(type, emptyQuery, null, {term: true}, function(err, queryELS) { 71 | console.log('emptyQuery ->', JSON.stringify(queryELS)); 72 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 73 | }); 74 | 75 | 76 | console.log('return: simpleQuery ->', JSON.stringify(elsGeneratorQueries.generate(type, simpleQuery, null, {term: true}))) 77 | elsGeneratorQueries.generate(type, simpleQuery, null, {term: true}, function(err, queryELS) { 78 | //console.log('simpleQuery ->', JSON.stringify(queryELS)); 79 | console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 80 | }); 81 | 82 | elsGeneratorQueries.generate(type, simpleQuery, null, {match: true}, function(err, queryELS) { 83 | console.log('simpleQuery (match) ->', JSON.stringify(queryELS)); 84 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 85 | }); 86 | 87 | console.log('return: simpleQuerySameField (with query_string) ->', JSON.stringify(elsGeneratorQueries.generate(type, simpleQuerySameField, null, {query_string: true}))) 88 | elsGeneratorQueries.generate(type, simpleQuerySameField, null, {term: true}, function(err, queryELS) { 89 | console.log('simpleQuerySameField ->', JSON.stringify(queryELS)); 90 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 91 | }); 92 | 93 | elsGeneratorQueries.generate(type, rangeQuery, null, {term: true}, function(err, queryELS) { 94 | console.log('rangeQuery ->', JSON.stringify(queryELS)); 95 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 96 | }); 97 | 98 | elsGeneratorQueries.generate(type, orQuery, null, {term: true}, function(err, queryELS) { 99 | console.log('orQuery -> ', JSON.stringify(queryELS)); 100 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 101 | }); 102 | 103 | elsGeneratorQueries.generate(type, notQuery, null, {term: true}, function(err, queryELS) { 104 | console.log('notQuery ->', JSON.stringify(queryELS)); 105 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 106 | }); 107 | 108 | elsGeneratorQueries.generate(type, multipleRange, null, {match: true}, function(err, queryELS) { 109 | console.log('multipleRange ->', JSON.stringify(queryELS)); 110 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 111 | }); 112 | 113 | elsGeneratorQueries.generate(type, complexQuery, null, {match: true}, function(err, queryELS) { 114 | console.log('complexQuery ->', JSON.stringify(queryELS)); 115 | // console.log("curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'" + JSON.stringify(queryELS) + "'"); 116 | }); 117 | 118 | --------------------------------------------------------------------------------