With a MongoDB collection structured like this:
{
title: {
lang1: "Title in lang1",
lang2: "Title in lang2"
},
description: {
lang1: "Description in lang1",
lang2: "Description in lang2"
},
keywords: ['keyword1','keyword2']
}
What is the best index structure for this query :
{$or: [
{"title.lang1": /searchTerm/i},
{"title.lang2": /searchTerm/i},
{"description.lang1": /searchTerm/i},
{"description.lang2": /searchTerm/i},
{"keywords": /searchTerm/i},
]}
What I have tested so far (using MongoDB Compass):
- Option 1 : no index. I got a warning
No index available for this query.
. - Option 2 : create a compound index on all these fields. I got a warning
No index available for this query.
. - Option 3 : create an index per field, I got a warning
Shard results differ
. Query is slower than options 1 or 2.
Is there an efficient option for this use case?
PS: Using Text Index is not an option as regex searches are required for fuzzy search (search terms are tokenized).
EDIT: In this video from MongoDB Atlas team you can see some quite fast fuzzy search in action performed with a feature called Full Text Search available on MongoDB Atlas (paid hosted solution). I want to achieve a similar feature with the free Community Server. The presenter Eliot Horowitz is talking about embedding Lucene in MongoDB. Maybe that's the only way?