0

Suppose that I have the below simplified schema:

const Venue = new mongoose.Schema(
  {
    name: {
      en: { type: String, required: true }, // English translation
      fr: { type: String, required: true }, // French translation
      es: { type: String, required: true }, // Spanish translation
      sw: { type: String, required: true },
    },
    country: {
      en: { type: String, required: true }, // English translation
      fr: { type: String, required: true }, // French translation
      es: { type: String, required: true }, // Spanish translation
      sw: { type: String, required: true },
    },
    countryIso3: String,
  },
  { collection: 'Venues', timestamps: true }
);

export default mongoose.models.Venue || mongoose.model('Venues', Venue);

So, I want to use one index definition that support dual-purpose fields (autocomplete + text search). How to do that by providing also the highlight score and inject the score boost during aggregation?

1
  • This is a cool use case. I’ve had to handle something similar — combining autocomplete and full text search in Mongo isn’t straightforward with a single index. What worked for me was using a $search stage from Atlas Search with a compound index: use autocomplete for user input and text for broader matching. Then you can boost scores inside the compound using score > boost > value, and even include highlights with highlight: { path: [...] }. Curious how others optimize this too! Commented Jul 20 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.