Reputation: 1937
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"
}
Upvotes: 1
Views: 3246
Reputation: 31
For your information, you need to create separate indices for your queries to work. If you create a single compound index you'll get the error.
Example:
This work
YourSchema.index({ randomValue: 1 })
YourSchema.index({ text: $text })
This don't
YourSchema.index({ randomValue: 1, text: $text })
Upvotes: 1
Reputation: 1937
This is actually not possible. Refer - https://jira.mongodb.org/browse/SERVER-13803
Upvotes: 0
Reputation: 37058
You need to re-create the text index without _id
and name
. $**
covers all fields.
If you need text index in these 2 fields only, remove $**
from the index, so it should be like {"_id": "text", "name":"text"}
Upvotes: 1