Exercises: compound
minimumShouldMatch
🔗 Playground link: adjust minimumShouldMatchSolution
"minimumShouldMatch": 2
Increase minimumShouldMatch to increase precision of results.
filter
You've got Products, each with a name
and a category
. A user is looking for accessories for a "camera", not actual cameras. Let's guide the user:
Solution
You might first try adding an equals
on category
within compound.filter
:
filter: [
{
equals: {
path: "category",
value: "Accessories"
}
}
]
Which leads us to this, which isn't yet working: 🔗 Playground link: filter by category not working yet
Note the surprising effect of querying a path that was not indexed specifically for that operator!
Using equals
on a string field effectively requires that it be mapped as type token
:
{
"mappings": {
"dynamic": true,
"fields": {
"category": [
{
"type": "token"
}
]
}
}
}
With this final solution: 🔗 Playground link: filter by category solution