Skip to main content
Required ACL: search

Examples

public class Product
{
    public string ObjectID { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
    public float Price { get; set; }
}

public class RelatedProduct : Product, Algolia.Search.Models.Recommend.IRecommendHit
{
    public float Score { get; set; }
}

var requests = new List<Algolia.Search.Models.Recommend.RelatedProductsRequest> {
  new Algolia.Search.Models.Recommend.RelatedProductsRequest {
      IndexName = "INDEX_NAME",
      ObjectID = "your_object_id",
  }
}

var relatedProducts =
  recommendClient.GetRelatedProducts<RelatedProduct>(requests);

// Asynchronous
var relatedProducts =
  await recommendClient.GetRelatedProductsAsync<RelatedProduct>(requests);
options := recommend.NewRelatedProductsOptions("IndexName", "B018APC4LE", 0, nil, nil, nil)
res, err = recommendClient.GetRelatedProducts([]recommend.RelatedProductsOptions{options})
 class Product implements RecommendHit {
   String objectID;
   String name;
   Float score;

   @Nonnull
   @Override
   public Float getScore() { return score;}
   public void setScore(Float score) { this.score = score;}
     
   public String getObjectID() { return objectID; }
   public void setObjectID(String objectID) { this.objectID = objectID; }
     
   public String getName() { return name; }
   public void setName(String name) { this.name = name; }
 }

 RelatedProductsQuery query = new RelatedProductsQuery("yourIndexName", "yourObjectID");

 // Synchronous
 List<RecommendationsResult<Product>> recommendations = recommendClient.getRelatedProducts(Arrays.asList(query), Product.class);

 // Asynchronous
 CompletableFuture<List<RecommendationsResult<Product>>> recommendations = recommendClient.getRelatedProductsAsync(Arrays.asList(query), Product.class);
recommendClient
  .getRelatedProducts([
    {
      indexName: "INDEX_NAME",
      objectID: "your_object_id",
    },
  ])
  .then(({ results }) => {
    console.log(results);
  })
  .catch((err) => {
    console.log(err);
  });
val request = RelatedProductsQuery(
    indexName = IndexName("yourIndexName"),
    objectID = ObjectID("yourObjectID"),
)

recommendClient.getRelatedProducts(requests = listOf(request))
$recommendations = $recommend_client->getRelatedProducts([
  [
    'indexName' => 'INDEX_NAME',
    'objectID' => 'your_object_id',
  ],
]);
related_products = recommend_client.get_related_products(
    [
        {
            "indexName": "INDEX_NAME",
            "objectID": "your_object_id",
        },
    ]
)
recommendations = recommend_client.get_related_products(
  [
    {
      indexName: "INDEX_NAME",
      objectID: "your_object_id"
    }
  ]
)
 recommendClient.execute {
   val query = RelatedProductsQuery(
     indexName = "yourIndexName",
     objectID = "yourObjectID"
   )
   get relatedProducts  List(query)
 }
let options = RelatedProductsOptions(indexName: "IndexName", objectID: "B018APC4LE")
recommendClient.getRelatedProducts(options: [options]) { result in 
 if case .success(let response) = result {
   print("Response: \(response)")
 }
}

Parameters

requests
object[]
required

Response

results
object[]
List of results in the order they were submitted, one per query.Example:
JSON
{
  "results": [
    {
      "hits": [
        {
          // ...,
          "_score": 32.72
        }
      ],
    },
  ]
}

Response as JSON

This section shows the JSON response returned by the API. Each API client wraps this response in language-specific objects, so the structure may vary. To view the response, use the getLogs method. Don’t rely on the order of properties—JSON objects don’t preserve key order.
JSON
{
  "results": [
    {
      "hits": [
        {
          "_highlightResult": {
            "category": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "Men - T-Shirts"
            },
            "image_link": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "https://example.org/image/D05927-8161-111-F01.jpg"
            },
            "name": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "Jirgi Half-Zip T-Shirt"
            }
          },
          "_score": 32.72,
          "category": "Men - T-Shirts",
          "image_link": "https://example.org/image/D05927-8161-111-F01.jpg",
          "name": "Jirgi Half-Zip T-Shirt",
          "objectID": "D05927-8161-111",
          "position": 105,
          "url": "men/t-shirts/d05927-8161-111"
        }
      ],
      "processingTimeMS": 1,
    }
  ]
}
Last modified on March 23, 2026