# Creating another search from the value of a field in an initial search?

**URL:** <https://discuss.elastic.co/t/creating-another-search-from-the-value-of-a-field-in-an-initial-search/11241>\
**Category:** Elasticsearch\
**Created:** [March 21, 2013, 2:04pm UTC](https://discuss.elastic.co/t/creating-another-search-from-the-value-of-a-field-in-an-initial-search/11241 "2013-03-21T14:04:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teddy777](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Teddy777](https://discuss.elastic.co/u/Teddy777)\
**Post date:** [March 21, 2013, 2:04pm UTC](https://discuss.elastic.co/t/creating-another-search-from-the-value-of-a-field-in-an-initial-search/11241/1 "2013-03-21T14:04:23Z")

</div>

If I initially search my db and get back 3 documents.

Doc 1:  
field\_a : user1\_id

Doc 2:  
field\_a : user1\_id

Doc 3:  
field\_a : user2\_id

I then want to search using the value 'user2\_id'

Currently I achieve this with a search that gives me the 3 docs, take the  
value 'user2\_id' and research with a must not filter. Which is adequate but  
I feel like I have all the information to do it in one.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 21, 2013, 3:57pm UTC](https://discuss.elastic.co/t/creating-another-search-from-the-value-of-a-field-in-an-initial-search/11241/2 "2013-03-21T15:57:27Z")

</div>

Hiya

On Thu, 2013-03-21 at 07:04 -0700, Teddy777 wrote:

> If I initially search my db and get back 3 documents.
> 
> Doc 1:  
> field\_a : user1\_id
> 
> Doc 2:  
> field\_a : user1\_id
> 
> Doc 3:  
> field\_a : user2\_id
> 
> I then want to search using the value 'user2\_id'
> 
> Currently I achieve this with a search that gives me the 3 docs, take  
> the value 'user2\_id' and research with a must not filter. Which is  
> adequate but I feel like I have all the information to do it in one.

Essentially you are wanting to do a join. Elasticsearch doesn't support  
joins per se. You could look at using parent/child, which is a form of  
join, but it may come with more complexity than you need.

Doing the above in two queries is probably the best way of achieving  
what you need

clint

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Teddy777](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Teddy777](https://discuss.elastic.co/u/Teddy777)\
**Post date:** [March 21, 2013, 4:43pm UTC](https://discuss.elastic.co/t/creating-another-search-from-the-value-of-a-field-in-an-initial-search/11241/3 "2013-03-21T16:43:09Z")

</div>

HI, yeah ok thanks for that.  
On Thursday, 21 March 2013 14:04:23 UTC, Teddy777 wrote:

> If I initially search my db and get back 3 documents.
> 
> Doc 1:  
> field\_a : user1\_id
> 
> Doc 2:  
> field\_a : user1\_id
> 
> Doc 3:  
> field\_a : user2\_id
> 
> I then want to search using the value 'user2\_id'
> 
> Currently I achieve this with a search that gives me the 3 docs, take the  
> value 'user2\_id' and research with a must not filter. Which is adequate but  
> I feel like I have all the information to do it in one.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:45am UTC](https://discuss.elastic.co/t/creating-another-search-from-the-value-of-a-field-in-an-initial-search/11241/4 "2017-07-06T02:45:17Z")

</div>


