db.data.aggregate({ "$match" : { "$text" : { "$search" : "<text here>" } } },
{"$match" : {"doc_type": "PATENT"} },
{ "$group" :
{ "_id" :{"doc_type": "$doc_type" ,"title" : "$title", "player_name" : "$player_name", "player_type" : "INSTITUTION", "country_code" :"$country_code" },
"number_records" : { "$sum" : 1}
}
},
{"$sort":{"number_records" : -1}},
{"$limit" : 10}
I am trying to executing the above text search aggregation, but this query is executing very slow or for some text query, it just keeps loading. am I doing any mistake?
$matchstage at the beginning as{ $match: { doc_type: "PATENT", $text: { $search: "<text here>" } }}. In that way the additional criteria is immediately made with the "text search" so you are not getting possible results that would be excluded by the other condition. You should also be specific about what you are expecting. Are you really looking for "text search" with relevance? Or are you just looking for a string present in one or possibly more fields? You want to $group later so it seems that "text search" is not likely what you really want