# Compare fields of different index

**URL:** https://discuss.elastic.co/t/compare-fields-of-different-index/11325
**Category:** Elasticsearch
**Created:** [March 26, 2013, 8:58pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325 "2013-03-26T20:58:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![harshyadav](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@harshyadav](https://discuss.elastic.co/u/harshyadav)
#### Post date: [March 26, 2013, 8:58pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325/1 "2013-03-26T20:58:44Z")

</div>

Please provide solution ASAP.  
I have two different index and i want to compare two fields value and get  
result which exist in different index

for example :-  
Index 1: message  
fields :- 1. message id  
2. message  
3. userid

Index 2: user  
fields:- 1. userid  
2. user name

Need query : Give messageid, message, username  
where message.userid = user.userid

I have tried script filter (query given below) but it is not working for  
different document

curl -XGET '[http://localhost:9200/test1\_index,test2\_index/\_search](http://localhost:9200/test1_index,test2_index/_search)' -d '  
{ "query":  
{ "filtered" : { "query" :  
{ "match\_all" : { } },  
"filter" :  
{ "script" :  
{"script" : "doc["msgid"].value ==  
doc["userid"].value" }  
}  
} }}'

--  
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: ![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 26, 2013, 9:13pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325/2 "2013-03-26T21:13:37Z")

</div>

I would say, index username in your message.  
That's how you should _think_ document.

Also, parent/child feature may help here...

My 2 cents (in ASAP answering mode 😉 ).

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 26 mars 2013 à 21:58, harry [harsh.mca9@gmail.com](mailto:harsh.mca9@gmail.com) a écrit :

> Please provide solution ASAP.  
> I have two different index and i want to compare two fields value and get result which exist in different index
> 
> for example :-  
> Index 1: message  
> fields :- 1. message id  
> 2. message  
> 3. userid
> 
> Index 2: user  
> fields:- 1. userid  
> 2. user name
> 
> Need query : Give messageid, message, username  
> where message.userid = user.userid
> 
> I have tried script filter (query given below) but it is not working for different document
> 
> curl -XGET '[http://localhost:9200/test1\_index,test2\_index/\_search](http://localhost:9200/test1_index,test2_index/_search)' -d '  
> { "query":  
> { "filtered" : { "query" :  
> { "match\_all" : { } },  
> "filter" :  
> { "script" :  
> {"script" : "doc["msgid"].value == doc["userid"].value" }  
> }  
> } }}'
> 
> --  
> 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).

--  
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: ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)
#### Post date: [March 26, 2013, 9:14pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325/3 "2013-03-26T21:14:00Z")

</div>

Currently the only way to do this is with parent/child functionality.. You  
will want user to be the parent and message to be the child. Then use a  
has parent query/filter.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Tue, Mar 26, 2013 at 1:58 PM, harry [harsh.mca9@gmail.com](mailto:harsh.mca9@gmail.com) wrote:

> Please provide solution ASAP.  
> I have two different index and i want to compare two fields value and get  
> result which exist in different index
> 
> for example :-  
> Index 1: message  
> fields :- 1. message id  
> 2. message  
> 3. userid
> 
> Index 2: user  
> fields:- 1. userid  
> 2. user name
> 
> Need query : Give messageid, message, username  
> where message.userid = user.userid
> 
> I have tried script filter (query given below) but it is not working for  
> different document
> 
> curl -XGET '[http://localhost:9200/test1\_index,test2\_index/\_search](http://localhost:9200/test1_index,test2_index/_search)' -d '  
> { "query":  
> { "filtered" : { "query" :  
> { "match\_all" : { } },  
> "filter" :  
> { "script" :  
> {"script" : "doc["msgid"].value ==  
> doc["userid"].value" }  
> }  
> } }}'
> 
> --  
> 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).

--  
Thanks,  
Matt Weber

--  
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: ![harshyadav](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@harshyadav](https://discuss.elastic.co/u/harshyadav)
#### Post date: [March 30, 2013, 10:32am UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325/4 "2013-03-30T10:32:47Z")

</div>

Thanx for quick reply.

I checked child parent queries and they have single index for different type doc and establish relationship between them but i have different index.

Would you please give me a simple example of it.  
It would be much helpful.

And How to index username in message??? I don't have any idea.

---

<div class="post-metadata">

### Author: ![harshyadav](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@harshyadav](https://discuss.elastic.co/u/harshyadav)
#### Post date: [March 30, 2013, 10:34am UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325/5 "2013-03-30T10:34:42Z")

</div>

Thanx for reply.

I checked child parent queries and they have single index for different type doc and establish relationship between them but i have different index.

Would you please give me a simple example of it.  
It would be much helpful.

---

<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:43am UTC](https://discuss.elastic.co/t/compare-fields-of-different-index/11325/6 "2017-07-06T02:43:29Z")

</div>


