This endpoint lets you search for documents by using advanced filters and free text queries. Free text queries are matched against the documents' filenames and contents.
The +
symbol represents an AND operation, and the |
symbol represents an OR.
Searching for lorem + ipsum
will match documents containing both "lorem" AND "ipsum" in the filename or content.
Similarly, searching for lorem | ipsum
will match documents containing either "lorem" OR "ipsum" in the filename or
content.
The default operator between the search keywords is AND.
That means that searching for two terms without any operator, for example, lorem ipsum
, will
match documents containing both the words "lorem" and "ipsum" in the filename or content.
You can use the operator -
to exclude documents containing a specific word.
For instance, the search lorem -ipsum
will match documents that contain the word "lorem", but does NOT contain the
word "ipsum".
Enclose multiple words inside double quotes "
to group these words together.
Normally, the search query lorem ipsum
will match not only "lorem ipsum" but also "lorem cognite ipsum",
and in general, there can be any number of words between the two words in the query.
The search query "lorem ipsum"
, however, will match only exactly "lorem ipsum" and not "lorem cognite ipsum".
To search for the special characters (+
, |
, -
, "
. \
), escape with a preceding backslash \
.
When you search for a term, the endpoint tries to return the most relevant documents first, with less relevant documents further down the list. There are a few factors that determine the relevance of a document:
The following request will return documents matching the specified search query.
{
"search": {
"query": "cognite \"lorem ipsum\""
}
}
The following example combines a query with a filter.
The search request will return documents matching the search query, where externalId
starts with "1".
The results will be ordered by how well they match the query string.
{
"search":{
"query":"cognite \"lorem ipsum\""
},
"filter":{
"prefix":{
"property":[
"externalId"
],
"value":"1"
}
}
}
When you enable highlights for your search query, the response contains an additional highlight field for each search hit, including the highlighted fragments for your query matches. However, the result limit is 20 documents due to the operation costs.
Filtering uses a special JSON filtering language.
It's quite flexible and consists of a number of different "leaf" filters, which can be combined arbitrarily using the boolean clauses and
, or
, and not
.
Leaf filter |
Supported fields |
Description |
---|---|---|
equals | Non-array type fields | Only includes results that are equal to the specified value.
|
in | Non-array type fields | Only includes results that are equal to one of the specified values.
|
containsAll | Array type fields | Only includes results which contain all of the specified values.
|
containsAny | Array type fields | Only includes results which contain all of the specified values.
|
exists | All fields | Only includes results where the specified property exists (has value).
|
prefix | String type fields | Only includes results which start with the specified value.
|
range | Non-array type fields | Only includes results that fall within the specified range.
Supported operators:
|
geojsonIntersects | geoLocation | Only includes results where the geoshape intersects with the specified geometry.
|
geojsonDisjoint | geoLocation | Only includes results where the geoshape has nothing in common with the specified geometry.
|
geojsonWithin | geoLocation | Only includes results where the geoshape falls within the specified geometry.
|
inAssetSubtree | assetIds , assetExternalIds | Only includes results with a related asset in a subtree rooted at any specified IDs.
|
search | name , content |
|
The following overview shows the properties you can filter and which filter applies to which property.
Property | Type | Applicable filters |
---|---|---|
["id"] |
integer | equals, in, range, exists |
["externalId"] |
string | equals, in, prefix, exists |
["instanceId"] |
string | equals, in |
| ["title"]
| string | equals, in, prefix, exists |
| ["author"]
| string | equals, in, prefix, exists |
| ["createdTime"]
| integer | equals, in, range, exists |
| ["modifiedTime"]
| integer | equals, in, range, exists |
| ["lastIndexedTime"]
| integer | equals, in, range, exists |
| ["mimeType"]
| string | equals, in, prefix, exists |
| ["extension"]
| string | equals, in, prefix, exists |
| ["pageCount"]
| integer | equals, in, range, exists |
| ["type"]
| string | equals, in, prefix, exists |
| ["geoLocation"]
| geometry object | geojsonIntersects, geojsonDisjoint, geojsonWithin, exists |
| ["language"]
| string | equals, in, prefix, exists |
| ["assetIds"]
| array of integers | containsAny, containsAll, exists, inAssetSubtree |
| ["assetExternalIds"]
| array of strings | containsAny, containsAll, exists, inAssetSubtree |
| ["labels"]
| array of Labels | containsAny, containsAll, exists |
| ["content"]
| string | search |
| ["sourceFile", "name"]
| string | equals, in, prefix, exists, search |
| ["sourceFile", "mimeType"]
| string | equals, in, prefix, exists |
| ["sourceFile", "size"]
| integer | equals, in, range, exists |
| ["sourceFile", "source"]
| string | equals, in, prefix, exists |
| ["sourceFile", "directory"]
| string | equals, in, prefix, exists |
| ["sourceFile", "assetIds"]
| array of integers | containsAny, containsAll, exists, inAssetSubtree |
| ["sourceFile", "assetExternalIds"]
| array of strings | containsAny, containsAll, exists, inAssetSubtree |
| ["sourceFile", "datasetId"]
| integer | equals, in, range, exists |
| ["sourceFile", "securityCategories"]
| array of integers | containsAny, containsAll, exists |
| ["sourceFile", "geoLocation"]
| geometry object | geojsonIntersects, geojsonDisjoint, geojsonWithin, exists |
| ["sourceFile", "labels"]
| array of Labels | containsAny, containsAll, exists |
| ["sourceFile", "metadata", <key>]
| string | equals, in, prefix, exists |
| ["sourceFile", "metadata"]
| string | equals, in, prefix, exists
This is a special filter field that targets all metadata values.
An alternative to creating a filter for each key in the metadata field. |
{
"filter": {
"and": [
{
"or": [
{
"equals": {
"property": [
"type"
],
"value": "PDF"
}
},
{
"prefix": {
"property": [
"externalId"
],
"value": "hello"
}
}
]
},
{
"range": {
"property": [
"createdTime"
],
"lte": 1519862400000
}
},
{
"not": {
"in": {
"property": [
"sourceFile",
"name"
],
"values": [
"My Document.doc",
"My Other Document.docx"
]
}
}
}
]
}
}
By default, search results are ordered by relevance, meaning how well they match the given query string. However, it's possible to specify a different property to sort by. Sorting can be ascending or descending. The sort order is ascending if none is specified.
The following overview shows all properties that can be sorted on.
Property |
---|
["id"] |
["externalId"] |
["mimeType"] |
["extension"] |
["pageCount"] |
["author"] |
["title"] |
["language"] |
["type"] |
["createdTime"] |
["modifiedTime"] |
["lastIndexedTime"] |
["sourceFile", "name"] |
["sourceFile", "mimeType"] |
["sourceFile", "size"] |
["sourceFile", "source"] |
["sourceFile", "datasetId"] |
["sourceFile", "metadata", *] |
{
"sort":[
{
"property":[
"createdTime"
],
"order":"asc",
}
]
}
Fields to be set for the search request.
The results of a search.
The response for a failed request.
{- "search": {
- "query": "cognite \"lorem ipsum\"",
- "highlight": false
}, - "filter": {
- "and": [
- {
- "prefix": {
- "property": [
- "name"
], - "value": "Report"
}
}, - {
- "equals": {
- "property": [
- "type"
], - "value": "PDF"
}
}
]
}, - "aggregates": [
- {
- "name": "countOfTypes",
- "aggregate": "count",
- "groupBy": [
- {
- "property": [
- "type"
]
}
]
}
], - "sort": [
- {
- "order": "asc",
- "property": [
- "sourceFile",
- "name"
]
}
], - "limit": 100,
- "cursor": "string",
- "highlight": true
}
{- "items": [
- {
- "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"
]
}, - "item": {
- "id": 2384,
- "externalId": "haml001",
- "instanceId": {
- "space": "string",
- "externalId": "string"
}, - "title": "Hamlet",
- "author": "William Shakespeare",
- "producer": "string",
- "createdTime": 1519862400000,
- "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"
}
], - "sourceFile": {
- "name": "hamlet.txt",
- "directory": "plays/shakespeare",
- "source": "SubsurfaceConnectors",
- "mimeType": "application/octet-stream",
- "size": 1000,
- "hash": "23203f9264161714cdb8d2f474b9b641e6a735f8cea4098c40a3cab8743bd749",
- "assetIds": [ ],
- "labels": [
- {
- "externalId": "my.known.id"
}
], - "geoLocation": {
- "type": "Point",
- "coordinates": [
- 10.74609,
- 59.91273
]
}, - "datasetId": 1,
- "securityCategories": [ ],
- "metadata": {
- "property1": "string",
- "property2": "string"
}
}, - "geoLocation": {
- "type": "Point",
- "coordinates": [
- 10.74609,
- 59.91273
]
}
}
}
], - "aggregates": [
- {
- "name": "string",
- "groups": [
- {
- "group": [
- {
- "property": [
- "sourceFile",
- "name"
], - "value": "string"
}
], - "count": 0
}
], - "total": 0
}
], - "nextCursor": "string"
}