How can I programmatically reindex Commerce products to AWS Elastic Search? I am using Drupal 8 Commerce module.
I am using Elastic Search on AWS platform.
From the Admin whenever product is saved, those changes are directly applied on Elastic Search server, but when I try with $product-&gt;save() it is not working 100%.
So if I have to update 10 products in Elastic Search how to achieve that programatically?
In particular, I have to update one field only. Because what is happening that, it will update that field value in database but not on Elastic Search.
I found this useful post for Node How To Force Search API To Reindex a Node / an Entity
So I have some updates answer relies in search_api.module file
function search_api_entity_update.
So I am able to achieve for one product. Can loop &amp; do for multiple.
use Drupal\commerce_product\Entity\Product;
use Drupal\search_api\Plugin\search_api\datasource\ContentEntity;

$entity = Product::load(1); // Replace 1 with your product id.

$indexes = ContentEntity::getIndexesForEntity($entity);

if (!$indexes) {
  return;
}

foreach ($indexes as $index) {
  $index-&gt;trackItemsUpdated('entity:commerce_product', ['1:en']);
}

It works like a charm :)