javaweaviatevector-database

How to retrieve the id of a object in weaviate java Client


i want to update an existing object in weaviate db. I find the object using neartext or using where filter, But i need object id to update, Any suggestion to do that, In python using _additional(id), id property can be retrieved.


Solution

  • package io.weaviate;
    
    import io.weaviate.client.Config;
    import io.weaviate.client.WeaviateClient;
    import io.weaviate.client.base.Result;
    import io.weaviate.client.v1.graphql.model.GraphQLResponse;
    import io.weaviate.client.v1.graphql.query.argument.NearTextArgument;
    import io.weaviate.client.v1.graphql.query.fields.Field;
    
    public class App {
      public static void main(String[] args) {
      Config config = new Config("http", "localhost:8080");
      WeaviateClient client = new WeaviateClient(config);
    
      Field title = Field.builder().name("title").build();
      Field _additional = Field.builder().name("_additional").fields(new Field[]{
        Field.builder().name("id").build(),
        Field.builder().name("distance").build()
      }).build();
    
    NearTextArgument explore = client.graphQL().arguments().nearTextArgBuilder()
      .concepts(new String[]{ "fashion" })
      .build();
    
    Result<GraphQLResponse> result = client.graphQL().get()
      .withClassName("Article")
      .withFields(title, _additional)
      .withNearText(explore)
      .run();
    if (result.hasErrors()) {
      System.out.println(result.getError());
      return;
    }
    System.out.println(result.getResult());  }   }
    

    found the solution from their documentation