0
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?

3
  • Try running explain command - stackoverflow.com/a/12702636/508214 Commented Nov 3, 2018 at 7:20
  • For starters you can use a single $match stage 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 Commented Nov 3, 2018 at 7:33
  • thanks for the reply, I am looking for the text search with relevant field. @NeilLunn Commented Nov 3, 2018 at 19:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.