Is it true that if a text index is used, a composite index cannot be used?
Because I used the following query statement but only did text indexing:
db.tests.find({$text:{$search:'zhangshan'},'age':5,'city':'beijing'}
Looking through explain, he has indexed the text. Then filter out other conditions from this index!
So what should I do to index them all?
I thought of creating a text index for all fields. Because of the large amount of data, I have not tried it. I would like to ask if this is feasible?
Thanks
Add explain()
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 50424,
"executionTimeMillis" : 510228,
"totalKeysExamined" : 83546,
"totalDocsExamined" : 167092,
"executionStages" : {
"stage" : "FETCH",
"filter" : {
"$and" : [
{
"age" : {
"$eq" : "5"
}
},
{
"city" : {
"$eq" : "beijing"
}
}
]
},
"nReturned" : 50424,
"executionTimeMillisEstimate" : 509543,
"works" : 167095,
"advanced" : 50424,
"needTime" : 116670,
"needYield" : 0,
"saveState" : 24418,
"restoreState" : 24418,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 83546,
"alreadyHasObj" : 83546,
"inputStage" : {
"stage" : "TEXT",
"nReturned" : 83546,
"executionTimeMillisEstimate" : 509362,
"works" : 167095,
"advanced" : 83546,
"needTime" : 83548,
"needYield" : 0,
"saveState" : 24418,
"restoreState" : 24418,
"isEOF" : 1,
"invalidates" : 0,
"indexPrefix" : {
},
"indexName" : "banner_text",
"parsedTextQuery" : {
"terms" : [
"ii"
],
"negatedTerms" : [ ],
"phrases" : [ ],
"negatedPhrases" : [ ]
},
"textIndexVersion" : 3,
"inputStage" : {
"stage" : "TEXT_MATCH",
"nReturned" : 83546,
"executionTimeMillisEstimate" : 509320,
"works" : 167095,
"advanced" : 83546,
"needTime" : 83548,
"needYield" : 0,
"saveState" : 24418,
"restoreState" : 24418,
"isEOF" : 1,
"invalidates" : 0,
"docsRejected" : 0,
"inputStage" : {
"stage" : "TEXT_OR",
"nReturned" : 83546,
"executionTimeMillisEstimate" : 509310,
"works" : 167095,
"advanced" : 83546,
"needTime" : 83548,
"needYield" : 0,
"saveState" : 24418,
"restoreState" : 24418,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 83546,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 83546,
"executionTimeMillisEstimate" : 1642,
"works" : 83547,
"advanced" : 83546,
"needTime" : 0,
"needYield" : 0,
"saveState" : 24418,
"restoreState" : 24418,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"_fts" : "text",
"_ftsx" : 1
},
"indexName" : "name_text",
"isMultiKey" : true,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "backward",
"indexBounds" : {
},
"keysExamined" : 83546,
"seeks" : 1,
"dupsTested" : 83546,
"dupsDropped" : 0,
"seenInvalidated" : 0
}
}
世界只因有你2017-05-24 11:33:30
Try to answer:
1. First of all, I want to see how your compound index is specifically established?
2. The execution result is executed according to the selected execution plan; if the performance is not satisfactory, you can use hint to specify the composite index you created.
Love MongoDB! Have fun!
The 2017 MongoDB Chinese Community Beijing User Group Conference is coming soon, June 3, 2017 13:00-18:00
Many wonderful sharings! Worth participating!