π Exercises
Only make searchable a specific subset of fieldsβ
π Playground link: a dynamic string field is automatically searchableMake it so only fields under the metadata
structure are indexed (and thus this query would then fail to find any matching documents). This is an exercise where no matching documents (an empty array []
) is the goal, rather than matching on a field that should not be indexed.
Solution
Turn off top-level dynamic mapping, and only index the metadata
sub-structure.
{
"mappings": {
"dynamic": false,
"fields": {
"metadata": [
{
"type": "document",
"dynamic": true
}
]
}
}
}