How to get all fields from indexes endpoint?

I have a use case where an user enters their mongoDB index name and we show them their index’s mappings.

For this, I am using this endpoint which returns the index details for the passed index including the schema.

However, the mappings returned doesn’t contain the field types and names all the time. If the mapping is set to dynamic: true then no field names are returned in the response.

Following is what I am getting right now for an index that has dynamic mapping set:

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

Following is what I want to get from the endpoint (mappings even if the dynamic mapping is set to true):

{
  "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"
}

Basically, I want a way to get all the fields for an index regardless of the dynamic field being set to true. Is this possible through the API?

1 Like