Mogodb uses a text index, can’t it use a composite index?

  mongodb, question

Is it not possible to use a compound index if a text index is used?
Because I used the following query statement but only did the text index:

db.tests.find({$text:{$search:'zhangshan'},'age':5,'city':'beijing'}

According to explain, he did the index of text. Then filter out other conditions from this index!
So what can I do to go through all the indexes?
I want to create a text index for all fields. Because of the large amount of data, I didn’t try. Do you want to ask if this is feasible?
Thank you


Add an explanation ()

"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
 }
 }

Try to answer:

1. First of all, I would like to see how your composite index is 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 2017MongoDB Chinese Community Beijing User Group Conference is approaching, June 3, 2017, 13: 00-18: 00

Many wonderful sharing! Worth participating!

图片描述