How to fetch data from multi indices based on condition

Dear All.

i have two indices Index01 and index02.

Condition 01:-1:
in index01 have ducument/column id(1211) that is matching with index02.

Condition 02:-1:
in index02 we have same document/column id(1211) but i want to display index02 document/column only like-firstname,lastname,dob based on matching HP(1111).

Data01/index01
id location ph HP
1211 UK 0977 1111
1212 UK 0933 2222

Data02/index02
FN LN DOB id
lal pal 12301999 1211
hapl oue 12041988 1212

I want only FETCH data when Provide HP=1111 THEN display records
FN LN DOB ID

Thanks

If you only need to lookup a single document in index02, than yes, you can use Terms Query. Take a look into settings index and id.

Hi @thiago .

Thanks

but i need query for that i tried more but not luck on two different indices .

Thanks

Unfortunately you can't query, you need to know the ID to be fetched from the other index by advance.

FYI that's the closest to a join you can get in Elasticsearch besides the nested and parent/child mappings.

Hi @thiago .

Thanks

then how can i implement the same use case please help by using nested or parent/child?

Thanks

This is a whole different approach, you would need to check if it's valid for your use case. First, you need to have a sense of what's the "main" index, let's say it's index01. With that defined, you will need to reindex index01 and there would be no index02. While reindexing index01 it would need to already join, during indexing, with index02 given that the joined resulting document would not have many documents from index02 (10s are fine, close or higher then 100s would maybe cause memory issues). Now, if you only need to query documents from index01 with a matching document in the inner collection with documents from index02 in which the query uses just a single attribute, then you are fine, but if the query is complex then you will need either Nested or Join.

See this for more on how to map 1-N: https://www.elastic.co/guide/en/elasticsearch/guide/current/modeling-your-data.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.