# Search in index using other index field

**URL:** <https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017>\
**Category:** Elasticsearch\
**Created:** [March 15, 2012, 3:25pm UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017 "2012-03-15T15:25:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [March 15, 2012, 3:25pm UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/1 "2012-03-15T15:25:51Z")

</div>

Hi all!

I'm facing a problem, and I would like to know if anyone knows a solution.  
So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.

What I would like to do is: use one field from my\_index1 docs to filter  
documents from my\_index2.  
Can I do this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Radu\_Gheorghe1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe1/32/2688_2.png) [@Radu\_Gheorghe1](https://discuss.elastic.co/u/Radu_Gheorghe1)\
**Post date:** [March 16, 2012, 7:44am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/2 "2012-03-16T07:44:22Z")

</div>

Hi Vania,

Maybe it's just me, but I'm not sure exactly what you're trying to  
achieve. Can you give an example?

On Mar 15, 5:25 pm, "Vania S." [vann...@gmail.com](mailto:vann...@gmail.com) wrote:

> Hi all!
> 
> I'm facing a problem, and I would like to know if anyone knows a solution.  
> So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.
> 
> What I would like to do is: use one field from my\_index1 docs to filter  
> documents from my\_index2.  
> Can I do this?
> 
> Thanks in advance!

---

<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 16, 2012, 7:52am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/3 "2012-03-16T07:52:04Z")

</div>

Hiya

> I'm facing a problem, and I would like to know if anyone knows a  
> solution.  
> So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.
> 
> What I would like to do is: use one field from my\_index1 docs to  
> filter documents from my\_index2.

The only way to do this is to run two queries: the first on my\_index1 to  
get the values you want to filter on, then the second on my\_index2, with  
those values passed in to the query.

clint

> Can I do this?
> 
> Thanks in advance!

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [March 16, 2012, 10:42am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/4 "2012-03-16T10:42:45Z")

</div>

Hi!

Thanks for the replies!

Radu, here goes an example:

In index2 I have some docs with a field called clientId.  
In index1 I have a list of docs with 2 fields: clientName and clientId.

The indexes sources are different and index2 is a narrowed list of clients.  
What I want to do is something like:  
"give me all documents of index1 where clientId is equal do documents in  
index2".

Clinton,

Thanks for the reply, but I'm trying not to bring the results to the  
elastic client.  
Doing 2 queries means that I have to bring both results to client side, and  
this might be really heavy.

Thanks!

On Thursday, March 15, 2012 3:25:51 PM UTC, Vania S. wrote:

> Hi all!
> 
> I'm facing a problem, and I would like to know if anyone knows a solution.  
> So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.
> 
> What I would like to do is: use one field from my\_index1 docs to filter  
> documents from my\_index2.  
> Can I do this?
> 
> Thanks in advance!

---

<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:** [March 16, 2012, 10:50am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/5 "2012-03-16T10:50:52Z")

</div>

Why don't you index client name in index 1 instead of it's id ?

David 😉  
@dadoonet

Le 16 mars 2012 à 11:42, "Vania S." [vannyas@gmail.com](mailto:vannyas@gmail.com) a écrit :

> Hi!
> 
> Thanks for the replies!
> 
> Radu, here goes an example:
> 
> In index2 I have some docs with a field called clientId.  
> In index1 I have a list of docs with 2 fields: clientName and clientId.
> 
> The indexes sources are different and index2 is a narrowed list of clients. What I want to do is something like:  
> "give me all documents of index1 where clientId is equal do documents in index2".
> 
> Clinton,
> 
> Thanks for the reply, but I'm trying not to bring the results to the elastic client.  
> Doing 2 queries means that I have to bring both results to client side, and this might be really heavy.
> 
> Thanks!
> 
> On Thursday, March 15, 2012 3:25:51 PM UTC, Vania S. wrote:  
> Hi all!
> 
> I'm facing a problem, and I would like to know if anyone knows a solution.  
> So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.
> 
> What I would like to do is: use one field from my\_index1 docs to filter documents from my\_index2.  
> Can I do this?
> 
> Thanks in advance!

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [March 16, 2012, 10:54am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/6 "2012-03-16T10:54:44Z")

</div>

David,

The indexed information comes from different systems, and I don't have  
control over the structure of the information.  
I would like to do a "kind of join" between both indexes, because index2  
have a narrowed list of clients, and I want to get the information from  
index1 that matches information from index2.

Thanks!

On Thursday, March 15, 2012 3:25:51 PM UTC, Vania S. wrote:

> Hi all!
> 
> I'm facing a problem, and I would like to know if anyone knows a solution.  
> So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.
> 
> What I would like to do is: use one field from my\_index1 docs to filter  
> documents from my\_index2.  
> Can I do this?
> 
> Thanks in advance!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 17, 2012, 10:03am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/7 "2012-03-17T10:03:19Z")

</div>

The only way to do it is as clinton suggested, there is no built in join  
between indices.

On Fri, Mar 16, 2012 at 12:54 PM, Vania S. [vannyas@gmail.com](mailto:vannyas@gmail.com) wrote:

> David,
> 
> The indexed information comes from different systems, and I don't have  
> control over the structure of the information.  
> I would like to do a "kind of join" between both indexes, because index2  
> have a narrowed list of clients, and I want to get the information from  
> index1 that matches information from index2.
> 
> Thanks!
> 
> On Thursday, March 15, 2012 3:25:51 PM UTC, Vania S. wrote:
> 
> > Hi all!
> > 
> > I'm facing a problem, and I would like to know if anyone knows a solution.  
> > So, I have 2 indexes in elastisearch: my\_index1 and my\_index2.
> > 
> > What I would like to do is: use one field from my\_index1 docs to filter  
> > documents from my\_index2.  
> > Can I do this?
> > 
> > Thanks in advance!

---

<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, 3:35am UTC](https://discuss.elastic.co/t/search-in-index-using-other-index-field/7017/8 "2017-07-06T03:35:48Z")

</div>


