Document management

Prev Next

Perform insert (indexing), update, upsert, delete requests for documents. All requests use the POST method, and Domain must be created before performing the request.

  • By default, insert/upsert requests are made for indexing when a document does not exist, a document has been changed, or the dictionary has been changed resulting in a change in indexing.
  • If update_time is specified, actual changes are approved only if it is the same as or more recent than the update_time of the existing document.
  • Use utf-8 for requests.
  • In a single request, insert/upsert/update/delete can be requested all at once.
  • Requests are processed sequentially. (Parallel processing internally without mixing primary keys)
  • Maximum number of documents for uploading at once is 1000/5 MB, and bulk uploads can be done through Object Storage Document management.
  • Must update the auto complete index through auto complete setting and modification request after this request when using the auto complete feature.
POST https://cloudsearch.apigw.ntruss.com/CloudSearch/real/v1/domain/{name}/document/manage

Requests

Request parameters

Parameter name Required Type Service limits Description
name Yes string Existing Domain name

Request bodies

Field name Required Type Service limits Description
requests[] Yes Array Document request list
requests[].type Yes string Select one from insert, upsert, update, and delete Request type definition
requests[].update_time No string yymmddHHMMSS.ssssss
Example: 170807133300.000000
Recommended to specify the time the document was changed in the request
requests[].force No bool true, false Process the request unconditionally without comparing changes with the already indexed document and update_time
requests[].force_hash No bool true, false Ignore changes with the already indexed document and process the request if the update_time is the same or newer compared to the existing document, based on the comparison of update_time only
requests[].key No (Required when requesting update, delete) string Primary key of document
requests[].content No (Required when requesting insert, upsert, and update) object Must include the key corresponding to the main section Document to use for request (Object in the form of a Map with section name as the key and the values mapped to the key as value)

Responses

Field name Type Description Note
request_id string update_time value returned by indexer yymmddHHMMSS.ssssss
Example: 170807133300.000000
status.code number Request status 0: Succeeded, -1: Failed
status.message string Error message when failed
total_document_count number Number of individual requests included in the request

Response status

HTTP Status Desc
200 OK (Request complete)
200 status.code: -1 (Request failed)
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal Server Error

Request type

The primary key is the KEY section, and the requests with KEY as 1 are processed sequentially and since the requests with KEY as 1 and those with KEY as 2 are not related to each other, they are processed in parallel internally in the example below.

insert/upsert/delete/update can be bundled in a single request, and requests[x].content key, value pairs are all composed of strings for requested JSON file. (If used as a numeric type in the search engine, it is internally converted from a string to a numeric type.)

insert requests

If the document exists, request for indexing if the document has been changed. If the document does not exist, request for indexing. Consider that the document has changed when the morphological analysis has changed due to the modification of the dictionary or the term/document weight has changed.

When requesting indexing, it is a principle to provide the entire defined document in the content, however, if omitted except for the key defined as the primary key, an empty string is used.

Section defined as primary key must be included in the content.

{
   "requests" : [
      {
         "type" : "insert",
         "key": "1",
         "content" :
          {
            "URL": "http://naver.com/bbs/abc.php?bo_table=QnA&wr_id=321651",
            "KEY": "1",
            "ROOT_ID": "732303375144529937",
            "TITLE": "Testing JSONJSONJSONJSONJSONJSONJSONJSON.",
            "DATE": "2012-01-01T00:00:00+0900",
            "BODY_TEXT": "JSONJSONJSONJSONJSONJSONJSONJSON"
          }
      }
  ]
}

upsert requests

If the requested document already exists, it merge with the existing document and then operates the same as an insert. If the requested document is a new document, it is simply indexed.

primary key must be set in a separate key or must be included in the content.

{
   "requests" : [
      {
         "type" : "upsert",
         "key" : "1",
         "content" :
          {
            "URL": "http://naver.com/bbs/abc.php?bo_table=QnA&wr_id=321651",
            "KEY": "1",
            "ROOT_ID": "732303375144529937",
            "TITLE": "Testing JSONJSONJSONJSONJSONJSONJSONJSON.",
            "DATE": "2012-01-01T00:00:00+0900",
            "BODY_TEXT": "JSONJSONJSONJSONJSONJSONJSONJSON"
          }
      }
  ]
}

update requests

Partially update an existing document. If the requested document does not already exist, nothing happens.

{
   "requests" : [
      {
         "type" : "update",
         "key" : "2",
         "content" :
          {
            "ROOT_ID": "223",
            "DATE": "2017-01-01T00:00:00+0900"
          }
      }
  ]
}

delete requests

Delete requested document. If the requested document does not exist, nothing happens.

{
   "requests" : [
      {
         "type" : "delete",
         "key" : "2"
      }
  ]
}

Examples

Request examples - insert

POST https://cloudsearch.apigw.ntruss.com/CloudSearch/real/v1/domain/car_dev/document/manage

POST /CloudSearch/real/v1/domain/car_dev/document/manage HTTP/1.1
Host:cloudsearch.apigw.ntruss.com
Content-Type: application/json
x-ncp-apigw-signature-v2: cDwtHuQeGmwWyNmwlN6XIGA66zge4iMXvfoDQNna05g=
x-ncp-apigw-timestamp: 1545817618751
x-ncp-iam-access-key: teGTwtcSEGA7fu28BGGi

{
  "requests": [
    {
      "type": "insert",
      "content": {
        "docid": "car-10001",
        "brand": "Hyundai",
        "name": "2018 Santa Fe",
        "color": "black",
        "price": "2817",
        "type": "Mid-size"
      }
    },
    {
      "type": "insert",
      "content": {
        "docid": "car-10002",
        "brand": "Hyundai",
        "name": "2018 Grandeur",
        "color": "white",
        "price": "2618"
      }
    }
    ]
}

Response examples (Common)

{
  "result": "ok"
}