Chilkat Online Tools

Classic ASP / MongoDB Atlas / Update an Atlas Search Index

Back to Collection Items

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

set http = Server.CreateObject("Chilkat_9_5_0.Http")

http.DigestAuth = 1
http.Login = "username"
http.Password = "password"

' Use this online tool to generate code from sample JSON: Generate Code to Create JSON

' The following JSON is sent in the request body.

' {
'   "collectionName": "synonyms",
'   "database": "my_test",
'   "name": "default",
'   "mappings": {
'     "dynamic": true
'   },
'   "analyzer": "lucene.standard",
'   "synonyms": [
'     {
'       "name": "egSynonyms",
'       "source": {
'         "collection": "synonyms"
'       },
'       "analyzer": "lucene.standard"
'     }
'   ]
' }

set json = Server.CreateObject("Chilkat_9_5_0.JsonObject")
success = json.UpdateString("collectionName","synonyms")
success = json.UpdateString("database","my_test")
success = json.UpdateString("name","default")
success = json.UpdateBool("mappings.dynamic",1)
success = json.UpdateString("analyzer","lucene.standard")
success = json.UpdateString("synonyms[0].name","egSynonyms")
success = json.UpdateString("synonyms[0].source.collection","synonyms")
success = json.UpdateString("synonyms[0].analyzer","lucene.standard")

set sbRequestBody = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = json.EmitSb(sbRequestBody)

' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.PTextSb("PATCH","https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/fts/indexes/{{INDEX-ID}}",sbRequestBody,"utf-8","application/json",0,0)
If (http.LastMethodSuccess = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( resp.StatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( resp.BodyStr) & "</pre>"


%>
</body>
</html>

Curl Command

curl -X PATCH
	--digest -u 'username:password'
	-d '{
    "collectionName": "synonyms",
    "database": "my_test",
    "name": "default",
    "mappings": {
        "dynamic": true
    },
    "analyzer": "lucene.standard",
    "synonyms": [
        {
            "name": "egSynonyms",
            "source": {
                "collection": "synonyms"
            },
            "analyzer": "lucene.standard"
        }
    ]
}'
https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/fts/indexes/{{INDEX-ID}}

Postman Collection Item JSON

{
  "name": "Update an Atlas Search Index",
  "request": {
    "method": "PATCH",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"collectionName\": \"synonyms\",\n    \"database\": \"my_test\",\n    \"name\": \"default\",\n    \"mappings\": {\n        \"dynamic\": true\n    },\n    \"analyzer\": \"lucene.standard\",\n    \"synonyms\": [\n        {\n            \"name\": \"egSynonyms\",\n            \"source\": {\n                \"collection\": \"synonyms\"\n            },\n            \"analyzer\": \"lucene.standard\"\n        }\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{base_url}}/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/fts/indexes/{{INDEX-ID}}",
      "host": [
        "{{base_url}}"
      ],
      "path": [
        "api",
        "atlas",
        "{{version}}",
        "groups",
        "{{ProjectID}}",
        "clusters",
        "{{CLUSTER-NAME}}",
        "fts",
        "indexes",
        "{{INDEX-ID}}"
      ]
    },
    "description": "https://docs.atlas.mongodb.com/reference/api/fts-indexes-create-one/"
  },
  "response": [
  ]
}