[SERVER-31989] Explain for $text search should include weights Created: 15/Nov/17  Updated: 27/Dec/23

Status: Backlog
Project: Core Server
Component/s: Text Search
Affects Version/s: 3.4.10
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Danny Hatcher (Inactive) Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 2
Labels: qi-text-search
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query Integration
Participants:
Case:

 Description   

Most indexes have the indexed fields in the key document. Explain against these indexes will list the relevant fields in the keyPattern document. These fields can be used to help diagnose long-running queries.

"inputStage" : {
				"stage" : "IXSCAN",
				"keyPattern" : {
					"b" : 1
				},
				"indexName" : "b_1",

Instead of the indexed fields themselves, text indexes use "_fts" : "text" and _ftsx" : 1 in the key document. Thus, when running explain against these queries, it is impossible to tell what fields are in the index unless the default indexName is used.

"inputStage" : {
				"stage" : "IXSCAN",
				"keyPattern" : {
					"_fts" : "text",
					"_ftsx" : 1
				},
				"indexName" : "testName",

As the indexed fields will be represented in the weights document, adding the document to the explain output should accomplish the same effect as standard indexes.



 Comments   
Comment by Kyle Suarez [ 16/Nov/17 ]

Oops. I ran the listIndexes command, which includes the weights document; however on running an explain of a find with a $text search query it indeed does not include the weights. Thanks for explaining, daniel.hatcher!

Throwing this into Query Team Triage.

Comment by Kyle Suarez [ 16/Nov/17 ]

It looks like v3 text indexes in MongoDB 3.6 include this information:

> db.c.createIndex({x: "text"})
{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 1,
        "numIndexesAfter" : 2,
        "ok" : 1
}
> db.c.getIndexes()
[
        {
                "v" : 2,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "test.c"
        },
        {
                "v" : 2,
                "key" : {
                        "_fts" : "text",
                        "_ftsx" : 1
                },
                "name" : "x_text",
                "ns" : "test.c",
                "weights" : {
                        "x" : 1
                },
                "default_language" : "english",
                "language_override" : "language",
                "textIndexVersion" : 3
        }
]

I'm not sure what change introduced this, but if it isn't present in 3.4 we could consider backporting it depending on the complexity of the change.

Generated at Thu Feb 08 04:28:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.