Can I use one Azure Search Indexer to index multiple entities with the same Key?

657 Views Asked by At

Basically I got two datasources(cosmos db, azure sql), one index and two indexers.

Both indexers are sharing the same primary key which allows me to join the data from both sources into one index. The issue right now is that the cosmos db contains multiple entries with the same key that is used in the indexers as the primary key, which then by default(I assume) just flattens all entries with the same key and only indexes the latest one found. It runs without errors, but obviously entries are missing as only the last one found is indexed.

The only solution so far is that I index the cosmos db in another indexer using the unique key. I kinda wanted to avoid having multiple search queries, but seems this is the only solution, unless anyone's got a better idea. Thank you!

1

There are 1 best solutions below

2
Stanley Gong On

No, you can not use a same key for multiple docs , key is an unique ID of each doc for looking up. If you adding multiple doc with same key to your index , sys will act multiple update operations on the doc with that key so that you can see the last record only.

Maybe my case is similar as yours which will be helpful , this is my index : enter image description here

And this is the data in my cosmos db : enter image description here

as you can see, the itemid is the key of my index and its value in my cosmos db all are same which is 1 . In my case , I use the _rid value to replace the itemid value while creating data source by sql query below :

SELECT u._rid as itemid, u.FirstName , u.LastName,u.Email , u._ts FROM user u  where u._ts >= @HighWaterMark ORDER BY u._ts

enter image description here

As you can see, index has been imported and this issue is solved : enter image description here

With this way , you can import data to your original index without same key issue. If there is any misunderstanding or unclear , pls feel free to let me know .