cURL
curl --request POST \
--url https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query \
--header 'content-type: <content-type>' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"size": 123,
"query": {},
"consistentRead": false,
"includeVectors": false,
"sort": [
{}
],
"trackScores": false
}
'import requests
url = "https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query"
payload = {
"size": 123,
"query": {},
"consistentRead": False,
"includeVectors": False,
"sort": [{}],
"trackScores": False
}
headers = {
"content-type": "<content-type>",
"x-api-key": "<x-api-key>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'content-type': '<content-type>', 'x-api-key': '<x-api-key>'},
body: JSON.stringify({
size: 123,
query: {},
consistentRead: false,
includeVectors: false,
sort: [{}],
trackScores: false
})
};
fetch('https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query",
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([
'size' => 123,
'query' => [
],
'consistentRead' => false,
'includeVectors' => false,
'sort' => [
[
]
],
'trackScores' => false
]),
CURLOPT_HTTPHEADER => [
"content-type: <content-type>",
"x-api-key: <x-api-key>"
],
]);
$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://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query"
payload := strings.NewReader("{\n \"size\": 123,\n \"query\": {},\n \"consistentRead\": false,\n \"includeVectors\": false,\n \"sort\": [\n {}\n ],\n \"trackScores\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("content-type", "<content-type>")
req.Header.Add("x-api-key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query")
.header("content-type", "<content-type>")
.header("x-api-key", "<x-api-key>")
.body("{\n \"size\": 123,\n \"query\": {},\n \"consistentRead\": false,\n \"includeVectors\": false,\n \"sort\": [\n {}\n ],\n \"trackScores\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["content-type"] = '<content-type>'
request["x-api-key"] = '<x-api-key>'
request.body = "{\n \"size\": 123,\n \"query\": {},\n \"consistentRead\": false,\n \"includeVectors\": false,\n \"sort\": [\n {}\n ],\n \"trackScores\": false\n}"
response = http.request(request)
puts response.read_body{
"took": 123,
"maxScore": 123,
"total": 123,
"docs": [
{
"index": "<string>",
"score": 123,
"doc": {}
}
]
}Documents
Query documents
Search an index with a query and return the most similar documents.
POST
/
projects
/
{projectId}
/
indexes
/
{indexName}
/
query
cURL
curl --request POST \
--url https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query \
--header 'content-type: <content-type>' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"size": 123,
"query": {},
"consistentRead": false,
"includeVectors": false,
"sort": [
{}
],
"trackScores": false
}
'import requests
url = "https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query"
payload = {
"size": 123,
"query": {},
"consistentRead": False,
"includeVectors": False,
"sort": [{}],
"trackScores": False
}
headers = {
"content-type": "<content-type>",
"x-api-key": "<x-api-key>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'content-type': '<content-type>', 'x-api-key': '<x-api-key>'},
body: JSON.stringify({
size: 123,
query: {},
consistentRead: false,
includeVectors: false,
sort: [{}],
trackScores: false
})
};
fetch('https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query",
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([
'size' => 123,
'query' => [
],
'consistentRead' => false,
'includeVectors' => false,
'sort' => [
[
]
],
'trackScores' => false
]),
CURLOPT_HTTPHEADER => [
"content-type: <content-type>",
"x-api-key: <x-api-key>"
],
]);
$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://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query"
payload := strings.NewReader("{\n \"size\": 123,\n \"query\": {},\n \"consistentRead\": false,\n \"includeVectors\": false,\n \"sort\": [\n {}\n ],\n \"trackScores\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("content-type", "<content-type>")
req.Header.Add("x-api-key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query")
.header("content-type", "<content-type>")
.header("x-api-key", "<x-api-key>")
.body("{\n \"size\": 123,\n \"query\": {},\n \"consistentRead\": false,\n \"includeVectors\": false,\n \"sort\": [\n {}\n ],\n \"trackScores\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{baseUrl}/{version}/projects/{projectId}/indexes/{indexName}/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["content-type"] = '<content-type>'
request["x-api-key"] = '<x-api-key>'
request.body = "{\n \"size\": 123,\n \"query\": {},\n \"consistentRead\": false,\n \"includeVectors\": false,\n \"sort\": [\n {}\n ],\n \"trackScores\": false\n}"
response = http.request(request)
puts response.read_body{
"took": 123,
"maxScore": 123,
"total": 123,
"docs": [
{
"index": "<string>",
"score": 123,
"doc": {}
}
]
}Body
application/json
Number of documents to return. Note that the maximum number of documents is 1000.
Query object.
If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.
If your application need to include vector values in the response, set includeVectors to true.
List of field name, sort direction pairs.
If your application needs to track scores with sorting, set trackScores to true.