Here’s a simple $search
stage sample.
{
index: "default",
compound: {
filter: [
{
range: {
path: "created_at",
lte: ISODate(
"2023-12-01T00:00:00.000Z"
),
gte: ISODate(
"2022-04-01T00:00:00.000Z"
),
},
},
],
should: [
{
text: {
query: "{{query}}",
fuzzy: {
maxEdits: 1,
prefixLength: 1,
},
path: {
wildcard: "properties.*",
},
},
},
{
text: {
query: "{{query}}",
fuzzy: {
maxEdits: 1,
prefixLength: 1,
},
path: "description",
},
},
],
},
count: {
type: "lowerBound",
threshold: 1000,
},
sort: {
created_at: 1
},
returnStoredSource: true,
highlight: {
path: ["description"],
maxCharsToExamine: 500,
maxNumPassages: 1,
},
}
And here are some sample documents:
{
"_id": {
"$oid": "63adcea85f7c5357a41c68d3"
},
"description": "User created",
"ip": "127.0.0.1",
"user_agent": "stensul/3.92.0.1 (core)",
"controller": "",
"action": "",
"properties": {
"user_id": "system",
"changed_user_id": {
"$oid": "63adcea75f7c5357a41c68d2"
},
"changed_user_name": "Germán",
"changed_user_last_name": "Medaglia",
"changed_user_email": "german.medaglia@stensul.com"
},
"updated_at": {
"$date": "2022-12-29T17:30:16.428Z"
},
"created_at": {
"$date": "2022-12-29T17:30:16.428Z"
}
}
{
"_id": {
"$oid": "63adcedc81cdce61285a2334"
},
"description": "User logged in",
"ip": "172.18.0.1",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"controller": "BaseLoginController",
"action": "postLogin",
"properties": {
"user_id": {
"$oid": "63adcea75f7c5357a41c68d2"
},
"email": "german.medaglia@stensul.com",
"method": "default"
},
"updated_at": {
"$date": "2022-12-29T17:31:08.572Z"
},
"created_at": {
"$date": "2022-12-29T17:31:08.572Z"
}
}