Search code examples
mongodbmongodb-querymongodb-java

MongoDB returning error - Failed to produce a solution for TEXT under OR - other non-TEXT clauses under OR have to be indexed as well


I am trying to run a query on MongoDB through Java Driver and I am getting this error -

"Query failed with error code 2 and error message 'error processing query: ns=Application.Team limit=10Tree: $or
_id == \"TEA000000006\"
TEXT : query=anonoymous, language=english, caseSensitive=0, diacriticSensitive=0, tag=NULL
Sort: { name: 1 }
Proj: { _id: 1, name: 1 }
Collation: { locale: \"en_US\", strength: 1 }
 planner returned error: Failed to produce a solution for TEXT under OR - 
 other non-TEXT clauses under OR have to be indexed as well.' on server 
 localhost:27017"

There seems to be some problem with the indexing I believe. If I do not give the sort or TEXT, it seems to work. Both together causes problem

I need the query to return records found in text search or if the ID is in the list passed (in this case, TEA0000006)

My Indices are -

{ 
    "v" : 2, 
    "name" : "myIndex", 
    "ns" : "Application.Team", 
    "weights" : {
         "$**" : 1, 
         "_id" : 1, 
         "name" : 1
    }, 
    "default_language" : "english", 
    "language_override" : "language", 
    "textIndexVersion" : 3
}

{ 
    "v" : NumberInt(2), 
    "key" : {
        "_id" : NumberInt(1)
    }, 
    "name" : "_id_", 
    "ns" : "Application.Team"
}

Solution

  • This is actually not possible. Refer - https://jira.mongodb.org/browse/SERVER-13803