# Is there way to pass dynamically built JSON query object to Elasticsearch?

**URL:** <https://discuss.elastic.co/t/is-there-way-to-pass-dynamically-built-json-query-object-to-elasticsearch/23423>\
**Category:** Elasticsearch\
**Created:** [April 27, 2015, 3:50pm UTC](https://discuss.elastic.co/t/is-there-way-to-pass-dynamically-built-json-query-object-to-elasticsearch/23423 "2015-04-27T15:50:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nithyanand](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@Nithyanand](https://discuss.elastic.co/u/Nithyanand)\
**Post date:** [April 27, 2015, 3:50pm UTC](https://discuss.elastic.co/t/is-there-way-to-pass-dynamically-built-json-query-object-to-elasticsearch/23423/1 "2015-04-27T15:50:44Z")

</div>

I am using angularjs and elasticsearch.angular.js. I have build a dynamic  
JSON query object based on user requests. Is there a way to in ES  
javascript to pass it to the search api?

In the below example, myJSONQUery is the JSON object.

client.search({  
index: 'myindex\*',  
body :{  
filtered : {  
myJSONQUery  
}  
}  
}).then(function (response) {  
console.info(JSON.stringify(response));  
});

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4d71025e-8a15-4a8c-889d-9202cfa25c74%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4d71025e-8a15-4a8c-889d-9202cfa25c74%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Nithyanand](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@Nithyanand](https://discuss.elastic.co/u/Nithyanand)\
**Post date:** [April 28, 2015, 4:35am UTC](https://discuss.elastic.co/t/is-there-way-to-pass-dynamically-built-json-query-object-to-elasticsearch/23423/2 "2015-04-28T04:35:25Z")

</div>

In another forum, I was given the option of Search templates. But I am  
dynamically building boolean "AND" and "OR" query based on name value pairs  
which are received as part of the request. In the case of same fields, the  
values we use "OR" and between different fields "AND". I have seen search  
template, but can we pass a query like this?

On Monday, April 27, 2015 at 9:20:44 PM UTC+5:30, Nithyanand wrote:

> I am using angularjs and elasticsearch.angular.js. I have build a dynamic  
> JSON query object based on user requests. Is there a way to in ES  
> javascript to pass it to the search api?
> 
> In the below example, myJSONQUery is the JSON object.
> 
> client.search({  
> index: 'myindex\*',  
> body :{  
> filtered : {  
> myJSONQUery  
> }  
> }  
> }).then(function (response) {  
> console.info(JSON.stringify(response));  
> });

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4027e7df-197c-476d-b870-e7ff4a0818df%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4027e7df-197c-476d-b870-e7ff4a0818df%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Nithyanand](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@Nithyanand](https://discuss.elastic.co/u/Nithyanand)\
**Post date:** [April 28, 2015, 6:15am UTC](https://discuss.elastic.co/t/is-there-way-to-pass-dynamically-built-json-query-object-to-elasticsearch/23423/3 "2015-04-28T06:15:01Z")

</div>

Hi, All who have pondered over this this question, thank you. I have solved  
this. The above request works. I had an issue because of the way my JSON  
Object was built. Please note the your JSON Object variable name becomes  
part of the request.

On Tuesday, April 28, 2015 at 10:05:25 AM UTC+5:30, Nithyanand wrote:

> In another forum, I was given the option of Search templates. But I am  
> dynamically building boolean "AND" and "OR" query based on name value pairs  
> which are received as part of the request. In the case of same fields, the  
> values we use "OR" and between different fields "AND". I have seen search  
> template, but can we pass a query like this?
> 
> On Monday, April 27, 2015 at 9:20:44 PM UTC+5:30, Nithyanand wrote:
> 
> > I am using angularjs and elasticsearch.angular.js. I have build a dynamic  
> > JSON query object based on user requests. Is there a way to in ES  
> > javascript to pass it to the search api?
> > 
> > In the below example, myJSONQUery is the JSON object.
> > 
> > client.search({  
> > index: 'myindex\*',  
> > body :{  
> > filtered : {  
> > myJSONQUery  
> > }  
> > }  
> > }).then(function (response) {  
> > console.info(JSON.stringify(response));  
> > });

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/feaf4de0-1322-42ca-99e9-8ac079cb6e2e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/feaf4de0-1322-42ca-99e9-8ac079cb6e2e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:17am UTC](https://discuss.elastic.co/t/is-there-way-to-pass-dynamically-built-json-query-object-to-elasticsearch/23423/4 "2017-07-06T00:17:31Z")

</div>


