Couchbase Search Active Queries REST API
- reference
Overview
The Search Active Queries REST API is provided by the Search service. This API enables you to get information about active Search queries.
Version information
Version : 7.6
Host information
{scheme}://{host}:{port}
The URL scheme, host, and port are as follows.
Component | Description |
---|---|
scheme |
The URL scheme. Use Values: |
host |
The host name or IP address of a node running the Search Service. Example: |
port |
The Search Service REST port. Use Values: |
Examples on this page
In the HTTP request examples:
-
$HOST
is the host name or IP address of a node running the Search Service. -
$USER
is the user name of an authorized user — see Security. -
$PASSWORD
is the password to connect to Couchbase Server.
Resources
This section describes the operations available with this REST API.
View Active Node Queries
GET /api/query
Description
Gets the details of all the active queries in any Search node in a cluster.
-
application/json
Parameters
Name | Description | Schema |
---|---|---|
longerThan |
Filters the queries running beyond the given span of time. The duration string is a signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as |
String (duration) |
Responses
HTTP Code | Description | Schema |
---|---|---|
200 |
A list of all active Search queries across all nodes in the cluster. |
Example HTTP Request
Request 2: Find all active queries across the Search cluster.
curl -XGET -H "Content-Type: application/json" \
-u $USER:$PASSWORD \
"http://$HOST:8094/api/query"
Request 3: Find all queries across the cluster that have been running for longer than 7s.
curl -XGET -H "Content-Type: application/json" \
-u $USER:$PASSWORD \
"http://$HOST:8094/api/query?longerThan=7s"
Example HTTP Response
Result of request 2.
{
"status": "ok",
"stats": {
"total": 3,
"successful": 3
},
"totalActiveQueryCount": 4,
"filteredActiveQueries": {
"queryCount": 4,
"queryMap": {
"b91d75480470f979f65f04e8f20a1f7b-17": {
"QueryContext": {
"query": {
"query": "good restaurants in france"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex1"
},
"executionTime": "2.144802122s"
},
"b91d75480470f979f65f04e8f20a1f7b-18": {
"QueryContext": {
"query": {
"query": "decent hotel with a pool in italy"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex2"
},
"executionTime": "2.144712787s"
},
"b91d75480470f979f65f04e8f20a1f7b-19": {
"QueryContext": {
"query": {
"query": "germany"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex2"
},
"executionTime": "2.143957727s"
},
"f76b2d51397feee28c1e757ed426ef93-3": {
"QueryContext": {
"query": {
"query": "mexican food in england"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex1"
},
"executionTime": "2.14286421s"
}
}
}
}
Result of request 3.
{
"status": "ok",
"stats": {
"total": 3,
"successful": 3
},
"totalActiveQueryCount": 3,
"filteredActiveQueries": {
"longerThan": "7s",
"queryCount": 1,
"queryMap": {
"b91d75480470f979f65f04e8f20a1f7b-21": {
"QueryContext": {
"query": {
"query": "decent hotel with a pool in italy"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex1"
},
"executionTime": "10.541956741s"
}
}
}
}
Cancel Active Queries
POST /api/query/{queryID}/cancel
Description
Allows the user to cancel an active query that's running longer than expected.
Use the View Active Index Queries API or the View Active Node Queries API to get the parameters queryID
and uuid
, which are used to identify and cancel the query.
-
application/json
-
application/json
Parameters
Name | Description | Schema |
---|---|---|
queryID |
The ID of the active query. This ID is used to identify the query that you want to cancel. |
Integer |
Name | Description | Schema |
---|---|---|
Body |
The body contains the UUID of the node where the query is running. This is optional and allows cancellation of queries on specific nodes. |
Example HTTP Request
Request 4: Cancel a long running query with query ID 24
whose coordinator node has a uuid b91d75480470f979f65f04e8f20a1f7b
.
curl -X POST -H "Content-Type: application/json" -u $USER:$PASSWORD \
"http://$HOST:8094/api/query/24/cancel" -d \
'{ "uuid": "b91d75480470f979f65f04e8f20a1f7b" }'
Example HTTP Response
Result of request 4.
{
"status": "ok",
"msg": "query with ID '24' on node 'b91d75480470f979f65f04e8f20a1f7b' was aborted!"
}
View Active Index Queries
GET /api/query/index/{indexName}
Description
Gets the details of all the active queries for any given Search index in the system.
-
application/json
Parameters
Name | Description | Schema |
---|---|---|
indexName |
The name of the Search index. |
String |
Name | Description | Schema |
---|---|---|
longerThan |
Filters the queries running beyond the given span of time. The duration string is a signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as |
String (duration) |
Example HTTP Request
Request 1: Find queries on the index DemoIndex1
that have been running for longer than 1 ms.
curl -XGET -H "Content-Type: application/json" \
-u $USER:$PASSWORD \
"http://$HOST:8094/api/query/index/DemoIndex1?longerThan=1ms"
Example HTTP Response
Result of request 1.
{
"status": "ok",
"stats": {
"total": 3,
"successful": 3
},
"totalActiveQueryCount": 4,
"filteredActiveQueries": {
"indexName": "DemoIndex1",
"longerThan": "1ms",
"queryCount": 2,
"queryMap": {
"b91d75480470f979f65f04e8f20a1f7b-16": {
"QueryContext": {
"query": {
"query": "good restaurants in france"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex1"
},
"executionTime": "1.059754811s"
},
"f76b2d51397feee28c1e757ed426ef93-2": {
"QueryContext": {
"query": {
"query": "mexican food in england"
},
"size": 10,
"from": 0,
"timeout": 120000,
"index": "DemoIndex1"
},
"executionTime": "1.058247896s"
}
}
}
}
Definitions
This section describes the properties consumed and returned by this REST API.
Active Response
Filtered Active Queries
Query Map
Query Map Item
Query Context
Stats
Cancellation Request
Cancellation Response
Active Response
Property | Schema | |
---|---|---|
status |
The status of the request. |
String |
stats |
An object containing request statistics. |
|
totalActiveQueryCount |
The total number of active queries. |
Integer |
filteredActiveQueries |
An object containing details of the filtered active queries. |
Filtered Active Queries
Property | Schema | |
---|---|---|
indexName |
The name of the Search index. Only included if viewing active queries for a specific index. |
String |
longerThan |
The duration used to filter the active queries.
Only included if the |
String (duration) |
queryCount |
The number of filtered active queries. |
Integer |
queryMap |
Contains 1 or more nested objects, each containing the details of a single active query. |
Query Map
Property | Schema | |
---|---|---|
additional |
The details of a single active query. The name of the property is the UUID of the node on which the query is running, and the ID of the query on that node, separated by a hyphen. |
Query Map Item
Property | Schema | |
---|---|---|
QueryContext |
The query context. |
|
executionTime |
The time taken to execute the query. |
String (duration) |
Query Context
Property | Schema | |
---|---|---|
query |
An object containing the Search query. For more information, see Search Request JSON Properties. |
Object |
size |
Example: |
Integer |
from |
Example: |
Integer |
timeout |
Example: |
Integer |
index |
The name of a Search index. |
String |
Stats
Property | Schema | |
---|---|---|
total |
Example: |
Integer |
successful |
Example: |
Integer |