# Querying elastic search through REST API with dynamic inputs

**URL:** <https://discuss.elastic.co/t/querying-elastic-search-through-rest-api-with-dynamic-inputs/174372>\
**Category:** Elasticsearch\
**Created:** [March 28, 2019, 3:03pm UTC](https://discuss.elastic.co/t/querying-elastic-search-through-rest-api-with-dynamic-inputs/174372 "2019-03-28T15:03:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maddysqlpro](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@maddysqlpro](https://discuss.elastic.co/u/maddysqlpro)\
**Post date:** [March 28, 2019, 3:03pm UTC](https://discuss.elastic.co/t/querying-elastic-search-through-rest-api-with-dynamic-inputs/174372/1 "2019-03-28T15:03:17Z")

</div>

Hi,  
Please help with the below scenario.

Scenario:  
The documents stored in ES will have keys "Key1" and "Key2". When from the application I send parameters for both Key1 and Key2 I need to do an "AND" condition and fetch the results. When only one parameter (Key1 or Key2) is supplied I need to query based on that key alone.

Question:  
Is there a way to achieve this in a ES directly in single query  
or in the rest api I need to construct the queries based on the inputs and execute accordingly.

---

<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:** [April 25, 2019, 3:07pm UTC](https://discuss.elastic.co/t/querying-elastic-search-through-rest-api-with-dynamic-inputs/174372/2 "2019-04-25T15:07:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
