Filtering multiple nested object vs multiple queries

Hello,
I am struggling to find the best way to make a query over 3 different models. Until this moment I found 2 different database structures to follow but I still don’t know which will help me get the most efficient query.
First structure looks like:

    {
        article: {
            name: "My custom article name",
            state: "published",
            samples: {
                  {sampleUID}: {
                         name: "Sample 1",
                         size: 200
                         variables: {
                               {varialbeUID}: {
                                       name: "Var1",
                                       type: "my type"
                               }
                               ...
                         }
                  }
                  ....
             }
        }
    }
And 2nd one is detached:
{
    article: {
        name: "My custom article name",
        state: "published",
    }
    sample: {
        name: "Sample 1",
        size: 200,
        article: {articleUID}
   }
   variable: {
        name: "Var1",
        type: "my type",
        sample: {sampleUID}
        article: {articleUID}
    }
}

And let’s say I would like to search for: Variables which has type like “my” which is contained by a sample with size > 100 which is contained in an article with state = published
Also it has to support a pagination. At least not to load all data at once. Should I get all data from DB and simulate the pagination on front end?

Note: I am able to make additional operations on frontend in order to show user relevant data. (like the one mentioned before).

I’d like to know what’s the best way to handle this kind of query.

Thanks for your help!

Hello @daniel1,

Both models should work since the Algolia filtering feature is able to perform the operation you want.

However, keep in mind that Algolia index structure is a non-relational, so you probably don’t need to split your structure into multiple virtual tables, if this is what you were expecting. I’d kindly recommend you to read this part of our documentation to better help you address this use-case Handling Data Relationships with Algolia.

Let us know if this does not help.