# How to build dynamic query of elasticsearch. which will execute on nodejs

**URL:** <https://discuss.elastic.co/t/how-to-build-dynamic-query-of-elasticsearch-which-will-execute-on-nodejs/47238>\
**Category:** Elasticsearch\
**Created:** [April 13, 2016, 11:18am UTC](https://discuss.elastic.co/t/how-to-build-dynamic-query-of-elasticsearch-which-will-execute-on-nodejs/47238 "2016-04-13T11:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smart.amit](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@smart.amit](https://discuss.elastic.co/u/smart.amit)\
**Post date:** [April 13, 2016, 11:18am UTC](https://discuss.elastic.co/t/how-to-build-dynamic-query-of-elasticsearch-which-will-execute-on-nodejs/47238/1 "2016-04-13T11:18:45Z")

</div>

When i tried to create query like on nodejs like

var my\_query = new Object("[{ "match": { "techskills.programming":"+ programming+" } }]");

var deferred = Q.defer();  
client.search({  
"index": \_index,  
"type": \_type,  
"body": {  
"query": {  
"bool": {  
"must": my\_query  
}  
}  
}  
},function (error,resp) {  
console.log("Found error is ::::: "+error + " resp::: "+JSON.stringify(resp));  
if(error) deferred.reject(error);  
deferred.resolve(resp);  
});  
return deferred.promise;

}

I am getting [query\_parsing\_exception] [bool] query does not support [must] error.  
How can i create dynamic query in elasticsearch so that i can append more criteria in query on runtime.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 14, 2016, 1:40pm UTC](https://discuss.elastic.co/t/how-to-build-dynamic-query-of-elasticsearch-which-will-execute-on-nodejs/47238/2 "2016-04-14T13:40:58Z")

</div>

Hey,

even though there are some helpers on NPM (just search for it), I think the easiest way is to create the JSON yourself and append to that JSON object, as mentioned in the [docs](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/quick-start.html#_elasticsearch_query_dsl)

Also if you show the HTTP query it might be easier to debug issues. See the [tracer logger type](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/logging.html#_logger_types)

--Alex

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:59pm UTC](https://discuss.elastic.co/t/how-to-build-dynamic-query-of-elasticsearch-which-will-execute-on-nodejs/47238/3 "2017-07-05T22:59:16Z")

</div>


