googleapis / google-cloud-java

Google Cloud Client Library for Java
https://cloud.google.com/java/docs/reference
Apache License 2.0
1.9k stars 1.07k forks source link

[v1-google-cloud-discoveryengine]: Still receiving as gRpc struct even use HttpJsonTransportProvider #10971

Open birbbie96 opened 5 months ago

birbbie96 commented 5 months ago

First of all, I'm very new with this service google-cloud-discoveryengine. I trying to call https://discoveryengine.googleapis.com/v1 for vertex search with client lib from google cloud and i want the result as json, btw i always receive struct which is not json response. So i go to read this documentation https://cloud.google.com/java/docs/reference/google-cloud-discoveryengine/latest/com.google.cloud.discoveryengine.v1.SearchServiceClient, they said that use
SearchServiceSettings searchServiceSettings = SearchServiceSettings.newHttpJsonBuilder().build(); but i still get struct response.

can u help me solve this problem? or tell me what i did wrong
this is my code

    SearchServiceSettings searchServiceSettings = SearchServiceSettings.newHttpJsonBuilder().build();
    try (SearchServiceClient searchServiceClient = SearchServiceClient.create(searchServiceSettings)) {
        SearchRequest request =
                SearchRequest.newBuilder()
                        .setServingConfig(
                                ServingConfigName.formatProjectLocationCollectionDataStoreServingConfigName(
                                        projectId, location, collectionId, dataStoreId, servingConfigId))
                        .setSpellCorrectionSpec(
                                SearchRequest.SpellCorrectionSpec.newBuilder()
                                        .setMode(SearchRequest.SpellCorrectionSpec.Mode.AUTO).build()
                        )
                        .setQueryExpansionSpec(
                                SearchRequest.QueryExpansionSpec.newBuilder()
                                        .setCondition(SearchRequest.QueryExpansionSpec.Condition.AUTO).build()
                        )
                        .setQuery(searchQuery)
                        .setPageSize(1)
                        .build();
        SearchServiceClient.SearchPagedResponse a =  searchServiceClient.search(request);
        SearchResponse response = a.getPage().getResponse();
        List<SearchResponse.SearchResult> results = response.getResultsList();
        SearchResponse.SearchResult res = results.getFirst();

this is some part of my response

results {
  id: "1250"
  document {
    name: "projects/272270411648/locations/global/collections/default_collection/dataStores/mordee-doctor-info-test/branches/0/documents/1250"
    id: "1250"
    struct_data {
      fields {
        key: "availableChannels"
        value {
          list_value {
            values {
              string_value: "Video"
            }
            values {
              string_value: "Voice"
            }
          }
        }
      }
      fields {
        key: "availableLanguages"
        value {
          list_value {
            values {
              string_value: "th-TH"
            }
          }
        }
      }
      fields {
        key: "certificate"
        value {
          struct_value {
            fields {
              key: "en"
              value {
                string_value: "Bachelor of Science Program in Food Technology and Nutrition, Mahasarakham University "
              }
            }
            fields {
              key: "th"
              value {
                string_value: "Master of Science Program in Food Technology, Khonkaen University "
              }
            }
          }
        }
      }

note* i try v1, v1beta, and v1alpha already

Java Version: java 22.0.1 Quarkus Version: 3.11.1

Thanks!

suztomo commented 5 months ago

i want the result as json

That "HttpJson" client setting is to specify the underlying communication procotol. From library's API's perspective, you won't see the difference between the underlying gRPC or JSON. Consider the API is the result after JSON parsing was already performed.

jegaths commented 5 months ago

Any luck on this? I am also facing similar problem.