Skip to content

Commit e050979

Browse files
committed
MDH: add "Prioritize preferred results" example
1 parent 76f4963 commit e050979

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/learn/master-data-hub/configuration-examples.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,35 @@ Even though using JavaScript can be easier in some scenarios, it is typically le
614614
}
615615
```
616616

617+
## Prioritize preferred results
618+
619+
The following query returns results as usual but sorts the preferred results above the rest:
620+
621+
```json
622+
{
623+
"aggregate": [
624+
{
625+
"$match": {
626+
"active": true,
627+
"country.code": "{country_code}"
628+
}
629+
},
630+
{
631+
"$addFields": {
632+
"__is_preferred_result": {
633+
"$eq": ["$internalId", "{preferred_result_id}"]
634+
}
635+
}
636+
},
637+
{
638+
"$sort": {
639+
"__is_preferred_result": -1
640+
}
641+
}
642+
]
643+
}
644+
```
645+
617646
## Remove duplicates (`$group`)
618647

619648
```json

0 commit comments

Comments
 (0)