# Search using result of previous search as parameter

**URL:** <https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203>\
**Category:** Elasticsearch\
**Created:** [November 27, 2017, 11:04am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203 "2017-11-27T11:04:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckhalilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ckhalilo/32/24716_2.png) [@ckhalilo](https://discuss.elastic.co/u/ckhalilo)\
**Post date:** [November 27, 2017, 11:04am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203/1 "2017-11-27T11:04:49Z")

</div>

Hi,

I need a help please, I have searched many topics and didn't find the answer.

I need to pass result of search as parameters like in SQL : `SELECT * FROM Table Where Field_1 = (SELECT Field_1 FROM Table WHERE Field_2 = 'searched_data')`

Here is my search in elasticsearch.

```
 GET _search
  {
  "query": {
    "query_string": {
    "default_field": "msgbody",
     "query": "searched_data"
   }
 },
 "_source": ["thread_name"],
 "size" : 1
}

```

I tried to pass in params but didn't find the right way:

```
 GET _search/template
 {
   "source" : {
    "query": { 
    "match_phrase" : { "{{my_field}}" : "{{my_value}}" }
     }
   },
 "params" : {
  "my_field" : "thread_name",
  "my_value" : "my_search_results"
  }
}

```

So my question is it possible to get result like SQL?

In case that's not possible, do you have any suggestion to get simular result?

## Best Regards

Khalil CHARFI

---

<div class="post-metadata">

**Author:** ![ckhalilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ckhalilo/32/24716_2.png) [@ckhalilo](https://discuss.elastic.co/u/ckhalilo)\
**Post date:** [November 28, 2017, 8:57am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203/2 "2017-11-28T08:57:11Z")

</div>

Up please any response will help me.

Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2017, 9:43am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203/3 "2017-11-28T09:43:29Z")

</div>

Please read

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

Specifically the "be patient" part.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2017, 9:44am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203/4 "2017-11-28T09:44:34Z")

</div>

You can't do that automatically so you need to solve that on your side (client side).  
You will end up doing multiple calls.

---

<div class="post-metadata">

**Author:** ![ckhalilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ckhalilo/32/24716_2.png) [@ckhalilo](https://discuss.elastic.co/u/ckhalilo)\
**Post date:** [November 28, 2017, 10:40am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203/5 "2017-11-28T10:40:09Z")

</div>

Thank you for your Help.

I know this is hard to answer every one.

I will be patient.

Best Regards

Khalil CHARFI

---

<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:** [December 26, 2017, 10:40am UTC](https://discuss.elastic.co/t/search-using-result-of-previous-search-as-parameter/109203/6 "2017-12-26T10:40:24Z")

</div>

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