cosmos
cosmos

Reputation: 2424

Storing fields with nested values in Apache SOLR

I have a Doc[id, text, creator, date] object which has a one-many relationship with Topic[name, description, sentiment] objects. Here is one way to design this schema

A fully flat structure, i.e. 1 field for each doc property and 3 fields each for each topic. So, if I have 5 topics for a doc, I will have 3*5=15 Topic fields. The problem is this is too flat and I am losing the hierarchy. Moreover, as every doc will have a different topic count, I have to allocate a large number of fields for topics irrespective of whether I need it or not. I guess this is not a problem in SOLR but it is not flexible from a programming and data storage point of view. Moreover, I also will like to query on each of this doc and topic properties.

Is there a better SOLR way which is more structured and hierarchical?

Upvotes: 0

Views: 479

Answers (1)

Persimmonium
Persimmonium

Reputation: 15771

As you say, flattening the docs is no problem at all in Solr, even though from a SQL standpoint looks wasteful.

But, if you want to keep a more SQL-like relationships, look at Block joins in Solr. I would go with flattening unless joins are strongly required, it would simplify your config.

Upvotes: 1

Related Questions