Skip to main content
POST
/
documents
/
search
JavaScript SDK
const documents = await client.documents.search({
  search: {
    query: 'Stuck pipe'
  },
  filter: {
    in: {
      property: ['type'],
      values: ['Document', 'PDF']
    }
  },
  limit: 5
});
from cognite.client.data_classes import filters
from cognite.client.data_classes.documents import DocumentProperty
is_pdf = filters.Equals(DocumentProperty.mime_type, "application/pdf")
documents = client.documents.search("pump 123", filter=is_pdf)

from datetime import datetime, timedelta
from cognite.client.data_classes import filters
from cognite.client.data_classes.documents import DocumentProperty
from cognite.client.utils import timestamp_to_ms
is_plain_text = filters.Equals(DocumentProperty.mime_type, "text/plain")
last_week = filters.Range(DocumentProperty.created_time,
gt=timestamp_to_ms(datetime.now() - timedelta(days=7)))
documents = client.documents.search('"CPLEX Error 1217: No Solution exists."',
highlight=True,
filter=filters.And(is_plain_text, last_week))
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/documents/search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filter": {
"and": [
{
"prefix": {
"property": [
"name"
],
"value": "Report"
}
},
{
"equals": {
"property": [
"type"
],
"value": "PDF"
}
}
]
},
"sort": [
{
"property": [
"sourceFile",
"name"
],
"order": "asc"
}
],
"limit": 100,
"cursor": "<string>",
"highlight": true
}
'
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/documents/search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'filter' => [
'and' => [
[
'prefix' => [
'property' => [
'name'
],
'value' => 'Report'
]
],
[
'equals' => [
'property' => [
'type'
],
'value' => 'PDF'
]
]
]
],
'sort' => [
[
'property' => [
'sourceFile',
'name'
],
'order' => 'asc'
]
],
'limit' => 100,
'cursor' => '<string>',
'highlight' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/documents/search"

payload := strings.NewReader("{\n \"filter\": {\n \"and\": [\n {\n \"prefix\": {\n \"property\": [\n \"name\"\n ],\n \"value\": \"Report\"\n }\n },\n {\n \"equals\": {\n \"property\": [\n \"type\"\n ],\n \"value\": \"PDF\"\n }\n }\n ]\n },\n \"sort\": [\n {\n \"property\": [\n \"sourceFile\",\n \"name\"\n ],\n \"order\": \"asc\"\n }\n ],\n \"limit\": 100,\n \"cursor\": \"<string>\",\n \"highlight\": true\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/documents/search")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"filter\": {\n \"and\": [\n {\n \"prefix\": {\n \"property\": [\n \"name\"\n ],\n \"value\": \"Report\"\n }\n },\n {\n \"equals\": {\n \"property\": [\n \"type\"\n ],\n \"value\": \"PDF\"\n }\n }\n ]\n },\n \"sort\": [\n {\n \"property\": [\n \"sourceFile\",\n \"name\"\n ],\n \"order\": \"asc\"\n }\n ],\n \"limit\": 100,\n \"cursor\": \"<string>\",\n \"highlight\": true\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/documents/search")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"filter\": {\n \"and\": [\n {\n \"prefix\": {\n \"property\": [\n \"name\"\n ],\n \"value\": \"Report\"\n }\n },\n {\n \"equals\": {\n \"property\": [\n \"type\"\n ],\n \"value\": \"PDF\"\n }\n }\n ]\n },\n \"sort\": [\n {\n \"property\": [\n \"sourceFile\",\n \"name\"\n ],\n \"order\": \"asc\"\n }\n ],\n \"limit\": 100,\n \"cursor\": \"<string>\",\n \"highlight\": true\n}"

response = http.request(request)
puts response.read_body
{
  "items": [
    {
      "item": {
        "id": 2384,
        "createdTime": 1519862400000,
        "sourceFile": {
          "name": "hamlet.txt",
          "directory": "plays/shakespeare",
          "source": "SubsurfaceConnectors",
          "mimeType": "application/octet-stream",
          "size": 1000,
          "hash": "23203f9264161714cdb8d2f474b9b641e6a735f8cea4098c40a3cab8743bd749",
          "assetIds": [],
          "labels": [
            {
              "externalId": "play"
            },
            {
              "externalId": "tragedy"
            }
          ],
          "geoLocation": {
            "type": "Point",
            "coordinates": [
              10.74609,
              59.91273
            ]
          },
          "datasetId": 4503599627370496,
          "securityCategories": [],
          "metadata": {}
        },
        "externalId": "haml001",
        "instanceId": {
          "space": "<string>",
          "externalId": "<string>"
        },
        "title": "Hamlet",
        "author": "William Shakespeare",
        "producer": "<string>",
        "modifiedTime": 1519958703000,
        "lastIndexedTime": 1521062805000,
        "mimeType": "text/plain",
        "extension": "pdf",
        "pageCount": 2,
        "type": "Document",
        "language": "en",
        "truncatedContent": "ACT I\nSCENE I. Elsinore. A platform before the castle.\n  FRANCISCO at his post. Enter to him BERNARDO\nBERNARDO\n  Who's there?\n",
        "assetIds": [
          42,
          101
        ],
        "labels": [
          {
            "externalId": "my.known.id"
          }
        ],
        "geoLocation": {
          "type": "Point",
          "coordinates": [
            10.74609,
            59.91273
          ]
        }
      },
      "highlight": {
        "name": [
          "amet elit <em>non diam</em> aliquam suscipit"
        ],
        "content": [
          "Nunc <em>vulputate erat</em> ipsum, at aliquet ligula vestibulum at",
          "<em>Quisque</em> lectus ex, fringilla aliquet <em>eleifend</em> nec, laoreet a velit.\n\nPhasellus <em>faucibus</em> risus arcu"
        ]
      }
    }
  ],
  "nextCursor": "<string>"
}
{
"error": {
"code": 401,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}

Authorizations

Authorization
string
header
required

Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.

Body

application/json

Fields to be set for the search request.

Filter with exact match

filter
and · object

A query that matches items matching boolean combinations of other queries. It is built using one or more boolean clauses, which can be of types: and, or or not

sort
object[]

List of properties to sort by. Currently only supports 1 property.

Required array length: 1 element
limit
integer<int32>
default:100

Maximum number of items. When using highlights the maximum value is reduced to 20.

Required range: 0 <= x <= 1000
cursor
string

Cursor for paging through results.

highlight
boolean

Whether or not matches in search results should be highlighted.

Response

The results of a search.

items
object[]
required
nextCursor
string

The cursor to get the next page of results (if available). The search endpoint only gives a limited number of results. A missing nextCursor does not imply there are no more results for the provided search.

Last modified on July 10, 2026