首页 > 解决方案 > Mongodb Atlas Search Autocomplete is slow on sort with large data set

问题描述

I have used an atlas search for finding Hashtags. I would like to sorting on t_status and count fields. t_status field does not exist in most of documents but it has exist in some documents.

Hashtags save in _id field.

search autocomplete index :

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "_id": {
        "foldDiacritics": false,
        "maxGrams": 10,
        "minGrams": 1, 
        "tokenization": "edgeGram",
        "type": "autocomplete"
      }
    }
  }
}

Search aggregate query :

[
  {
    '$search': {
      'index': 'default', 
      'autocomplete': {
        'query': 'a', 
        'path': '_id'
      }
    }
  }, {
    '$sort': {
      't_status': -1, 
      'count': -1
    }
  }, {
    '$limit': 20
  }
]

Above search query slow on sorting with huge data set.

Anyone can Give me the solution of this question?

标签: mongodbaggregation-frameworkmongodb-atlas-search

解决方案


推荐阅读