API endpoints for index list and mappings

Hey everyone

I had a use case for getting the list of indices and getting mappings on a per index basis. I have few questions regarding that:

  1. Is there a way to get all the indices in a cluster?

    I know about this doc but it points to requiring DATABASE_NAME and COLLECTION, but MongoDB cloud is able to query this without needing this. Is there a public / non-documented endpoint that can be used to do the same through REST API?

  2. How to get all the fields + types (i.e. mappings) in an Atlas Search index?

    I am aware of this endpoint but when the mappings is set to dynamic, it doesn’t return the fields in the response. I would like to have the fields returned as well. Is there a way to force returning fields even when dynamic is true?

Hi @Deepjyoti_Barman - Welcome to the community.

I had a use case for getting the list of indices and getting mappings on a per index basis.

Could you provide further details regarding the use case?

My interpretation of this question is that you want to get all the search index details for a particular cluster via the Atlas Administration API without needing to specify database or collection. Is this correct? If so, this is currently not possible as far as I am aware. However, as previously mentioned, it would be good to understand the use case for this. You could possibly create a script to connect using a driver (or possibly mongosh) and obtain a list of the databases and collections before passing this through to the Get All Atlas Search Indexes for a Collection API.

Do you have an example output that you could provide of what you are currently receiving in the response and what you’re expecting it to include?

Regards,
Jason

1 Like

We’re building an integration on top of Atlas Search, where we’re allowing an Atlas Search user to build a search UI against any index. It would be ideal to have one endpoint to get all the indices of the cluster v/s having to ask a user to specify their DB + Collection info additionally.I see this working as part of cloud.mongodb.com, but it’s an undocumented endpoint and I would like to know what Auth mechanism this supports to use it programatically.The call is a GET against: https://cloud.mongodb.com/nds/clusters/60cb67c0848c036fd17a281f/Cluster1/fts/indexes With a response that looks like:

[
   {
      "analyzer":null,
      "analyzers":null,
      "collectionName":"shipwrecks",
      "database":"sample_geospatial",
      "deleteRequestedDate":null,
      "indexID":"621f431f31ed037fb9790aa4",
      "lastUpdateDate":null,
      "mappings":{
         ...
      },
      "name":"geo",
      "searchAnalyzer":null,
      "stats":{
         ...
      },
      "status":"STEADY",
      "storedSource":null,
      "synonyms":null
   },
   ...
]

Following is what we are getting now:

{
  "collectionName" : "movies",
  "database" : "sample_mflix",
  "indexID" : "5d1268a980eef518dac0cf41",
  "mappings" : {
    "dynamic" : true
  },
 "name" : "SearchIndex1",
 "status" : "STEADY"
}

Following is what we expect:

{
  "collectionName" : "movies",
  "database" : "sample_mflix",
  "indexID" : "5d1268a980eef518dac0cf41",
  "mappings" : {
    "dynamic" : false,
    "fields" : {
      "genres" : {
        "analyzer" : "lucene.standard",
        "type" : "string"
      },
      "plot" : {
        "analyzer" : "lucene.standard",
        "type" : "string"
      }
    }
  },
 "name" : "SearchIndex1",
 "status" : "STEADY"
}

Hi @Deepjyoti_Barman , we currently do not support a command which returns all search indexes within the same cluster. Can you help me understand if @Jason_Tran 's suggested workaround (below) will work for you? If not, why? We’re working on making improvements to this experience and your feedback is very valuable

You could possibly create a script to connect using a driver (or possibly mongosh ) and obtain a list of the databases and collections before passing this through to the Get All Atlas Search Indexes for a Collection API.

Thanks!

@amyjian @Jason_Tran’s suggested solution is possible: It’s complexity being O(mxn), in practice this might mean a minute before the entire list of search indexes for a cluster can be retrieved. Our use-case is to display a UI selector for search indexes.

Having a direct endpoint that returns search indexes for a cluster would keep our implementation simple.

And it does seem you have it resolving as one endpoint in the MongoDB cloud UI where search indexes are displayed.

This UI is rendered based on this endpoint call: Cloud: MongoDB Cloud which returns all the indexes for the cluster in a ~1s time.

Is something similar possible as an API user as well? Currently, the best option I see is what Jason is suggesting, however having one endpoint to get all the search indexes if possible would solve for a quick response time.