Skip to main content
Weaviate Docs (migrated from docs.weaviate.io) Docs

Search documentation

Type to search this documentation.

On this pageOverview

Read objects

Instead of querying your database, you can use an ID to retrieve individual objects.

Additional information

Use an ID to retrieve an object. If the id doesn't exist, Weaviate returns a 404 error.

Python
jeopardy = client.collections.use("JeopardyQuestion")data_object = jeopardy.query.fetch_object_by_id("00ff6900-e64f-5d94-90db-c8cfa3fc851b")print(data_object.properties)
JavaScript/TypeScript
const jeopardy = client.collections.use('JeopardyQuestion')

const response = await jeopardy.query.fetchObjectById('ed89d9e7-4c9d-4a6a-8d20-095cb0026f54')

console.log(response?.properties)
Go
objects, err := client.Data().ObjectsGetter().
  WithClassName("JeopardyQuestion").
  WithID("00ff6900-e64f-5d94-90db-c8cfa3fc851b").
  Do(ctx)
if err != nil {
  // handle error
  panic(err)
}

for i, obj := range objects {
  fmt.Printf("object[%v]: %+v\n", i, *obj)
}
Java
CollectionHandle<Map<String, Object>> jeopardy = client.collections.use("JeopardyQuestion");var dataObjectOpt = jeopardy.query.fetchObjectById("00ff6900-e64f-5d94-90db-c8cfa3fc851b");dataObjectOpt.ifPresent(dataObject -> System.out.println(dataObject.properties()));
C#
var jeopardy = client.Collections.Use("JeopardyQuestion");var dataObject = await jeopardy.Query.FetchObjectByID(    Guid.Parse("00ff6900-e64f-5d94-90db-c8cfa3fc851b"));if (dataObject != null){    Console.WriteLine(JsonSerializer.Serialize(dataObject.Properties));}

Object vectors can be retrieved by specifying its return.

Python
jeopardy = client.collections.use("JeopardyQuestion")data_object = jeopardy.query.fetch_object_by_id(    "00ff6900-e64f-5d94-90db-c8cfa3fc851b",    include_vector=True)print(data_object.vector["default"])
JavaScript/TypeScript
const jeopardy = client.collections.use('JeopardyQuestion')const response = await jeopardy.query.fetchObjectById('ed89d9e7-4c9d-4a6a-8d20-095cb0026f54',{  includeVector: true})console.log(response?.properties)
Go
objects, err := client.Data().ObjectsGetter().  WithClassName("JeopardyQuestion").  WithID("00ff6900-e64f-5d94-90db-c8cfa3fc851b").  WithVector().  Do(ctx)if err != nil {  // handle error  panic(err)}for i, obj := range objects {  fmt.Printf("object[%v]: %+v\n", i, *obj)}
Java
CollectionHandle<Map<String, Object>> jeopardy = client.collections.use("JeopardyQuestion");var dataObjectOpt = jeopardy.query.fetchObjectById("00ff6900-e64f-5d94-90db-c8cfa3fc851b",    q -> q.includeVector());dataObjectOpt.ifPresent(dataObject -> System.out    .println(Arrays.toString(dataObject.vectors().getSingle("default"))));
C#
var jeopardy = client.Collections.Use("JeopardyQuestion");var dataObject = await jeopardy.Query.FetchObjectByID(    Guid.Parse("00ff6900-e64f-5d94-90db-c8cfa3fc851b"),    includeVectors: true);if (dataObject?.Vectors.ContainsKey("default") ?? false){    var vector = dataObject.Vectors["default"];    Console.WriteLine(vector);}

Where named vectors are used, you can retrieve one or more of them by specifying their names.

Python
reviews = client.collections.use("WineReviewNV")  # Collection with named vectors
JavaScript/TypeScript
const reviews = client.collections.use('WineReviewNV') // Collection with named vectorsconst objectUuid = '' // Object UUIDconst response = await reviews.query.fetchObjectById(objectUuid,{  includeVector: ['title', 'review_body']})console.log(response?.vectors.title)       // print the title vectorconsole.log(response?.vectors.review_body) // print the review_body vector
Java
CollectionHandle<Map<String, Object>> reviews = client.collections.use("WineReviewNV"); // Collection with named
C#
var reviews = client.Collections.Use("WineReviewNV"); // Collection with named

To efficiently check if an object with a given id exists without retrieving it, make a HEAD request to the /v1/objects/ REST endpoint, or use the following client code:

Python
# generate uuid based on the key properties used during data insert
object_uuid = generate_uuid5({"name": "Author to fetch"})
JavaScript/TypeScript
import { generateUuid5 } from 'weaviate-client';// generate uuid based on the key properties used during data insertconst object_uuid = generateUuid5(  JSON.stringify({ name: "Author to fetch"}))const authors = await client.collections.use('Author')const authorExists = await authors.data.exists(object_uuid)console.log('Author exists: ' + authorExists)
Go
package main

import (
  "context"
  "fmt"

  "github.com/weaviate/weaviate-go-client/v5/weaviate"
  "github.com/weaviate/weaviate-go-client/v5/weaviate/data/replication"  // for consistency levels
)

func main() {
  cfg := weaviate.Config{
    Host:   "localhost:8080",
    Scheme: "http",
  }
  client, err := weaviate.NewClient(cfg)
  if err != nil {
    panic(err)
  }

  exists, err := client.Data().Checker().
    WithClassName("MyClass").
    WithID("36ddd591-2dee-4e7e-a3cc-eb86d30a0923").
    WithConsistencyLevel(replication.ConsistencyLevel.ONE).  // default QUORUM
    Do(context.Background())

  if err != nil {
    panic(err)
  }
  fmt.Printf("%v", exists)
}

// The parameter passed to "WithConsistencyLevel" can be one of:
// * replication.ConsistencyLevel.ALL,
// * replication.ConsistencyLevel.QUORUM, or
// * replication.ConsistencyLevel.ONE.
//
// It determines how many replicas must acknowledge a request
// before it is considered successful.
Java
CollectionHandle<Map<String, Object>> jeopardy = client.collections.use("JeopardyQuestion");
boolean exists = jeopardy.data.exists("00ff6900-e64f-5d94-90db-c8cfa3fc851b");
System.out.println(exists);
C#
var jeopardy = client.Collections.Use("JeopardyQuestion");

// The C# client checks for existence by attempting to fetch an object and checking for null.
var dataObject = await jeopardy.Query.FetchObjectByID(
    Guid.Parse("00ff6900-e64f-5d94-90db-c8cfa3fc851b")
);
bool exists = dataObject != null;

Console.WriteLine(exists);

Have a question or feedback? Here's how to reach us.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu