Question

My schema looks something like:

{
    concepts: [
        {name:..., word:..., start:..., stop:...}
    ],
    text:...
}

I have a text index on the "text" field and a multi-key index on "concepts.name":

db.col.ensureIndex({text:"text"})
db.col.ensureIndex({"concepts.name":1})

When I run:

db.col.find({"concepts.name":"something"})

I get 10 results and 10 scans. But when I run:

db.col.find({"concepts.name":"something",$text:{$search:"querystring"}}):

I get less results but it takes longer and scans a much larger number of documents. I was expecting that the new index intersection feature of MongoDB 2.6 would automatically first cut it down to 10 documents and then do the text search on those. What am I missing? Is this even possible?

Was it helpful?

Solution

You'll need to create a compound index to support that query. MongoDB 2.6 Index intersection does not work with text indexes. There's an example here in the documentation.

db.col.ensureIndex({"concepts.name": 1, text: "text" })

Edit

As you point out though -- your example is using mutli-key, which is not supported when combined with a text index. Unfortunately, it's a limitation of MongoDB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top