Sort results by ranking

user6824632 Source

I am trying to search for a keyword in Mongo collection but results not sorted as per their after finding match, I am sorting by textscore using the code below In java code , I am writing


I am getting an error "pipeline requires text score metadata, but there is no text score available"

I have created a text index on the field.. appreciate if you can point me into right direction .

    public Document find(Map<String,String> params){    

    ProcessRequest request  = new ProcessRequest();
    MongoCollection<Document> mcollection = mconfig.getRecordCollection();
    long count  = mcollection.count(request.getFilter());"Count :"+count);
    AggregateIterable<Document> aggre = null;
     aggre = mcollection.aggregate(request.getQueryList());
    catch(Exception e){;
    Document resultDoc = new Document();
    resultDoc.put("ResultCount", count);
    resultDoc.put("PageSize", request.getPageSize());
    return resultDoc;


Thanks SK



answered 8 months ago Veeram #1

I found the bug report where the validation was added if text score is referenced without text search.

So you require to perform a text search to return the text score. Check your filter to see it includes text search.

ex: {$match: {$text: {$search: search term}}},

answered 8 months ago user6824632 #2

As I have added textscore to projections, only textscore is getting displayed.. commenting out projections displayed all the fields

comments powered by Disqus