Compare fields of different index

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' -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.
For more options, visit https://groups.google.com/groups/opt_out.

1 Like

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 :wink: ).

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 26 mars 2013 à 21:58, harry 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' -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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

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.

http://www.elasticsearch.org/guide/reference/mapping/parent-field/
http://www.elasticsearch.org/guide/reference/query-dsl/has-parent-query/

On Tue, Mar 26, 2013 at 1:58 PM, harry 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' -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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

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.

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.