Data Modeling for Search
https://www.mongodb.com/developer/products/atlas/data-modeling-for-search/
Techniques
consistent field types
Schema matters! A price is a number, never a string!!
Nested documents
Avoid embeddedDocuments when:
- There's only one field in them
- Matching on a flattened structure suffices
Entity pattern
"Data that is searched together is stored together" - sound familiar?
Documents represent what your application wants, so that the power of relevancy ranking and one to one capabilities of lexical analysis and matching tricks can work with field mappings and queries comfortably.
For example: if cast are first class citizens for the users, model them as such, and then search works well.
This pattern represents "entities" (in whatever way you want to define them) in a simple typed schema.
This is much like the Single Collection Pattern: https://www.mongodb.com/developer/products/mongodb/single-collection-pattern/
Entity documents
_id: unique identifier (as universal as possible, ideally)
type: a simple string value of your choosing: "cast", "genre", "title", or ... TBD
name: what do you call this thing? how would people find it? what is it called in words?
<etc>: any other useful fields needed for sorting, matching, filtering, ranking, or display
- Tips:
$mergecan be your good friend!
{
"mappings": {
"dynamic": false,
"fields": {
"metadata": [
{
"type": "document",
"dynamic": true
}
]
}
}
}