# Compare field value of different index

**URL:** <https://discuss.elastic.co/t/compare-field-value-of-different-index/11324>\
**Category:** Elasticsearch\
**Created:** [March 26, 2013, 8:52pm UTC](https://discuss.elastic.co/t/compare-field-value-of-different-index/11324 "2013-03-26T20:52:13Z")\
**Posts on this page:** 2\
**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:52pm UTC](https://discuss.elastic.co/t/compare-field-value-of-different-index/11324/1 "2013-03-26T20:52:13Z")

</div>

Hi ,  
Can you please guide me to the following problem,  
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" }  
}  
} }}'

---

<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:44am UTC](https://discuss.elastic.co/t/compare-field-value-of-different-index/11324/2 "2017-07-06T02:44:19Z")

</div>


