I am looking for a way to search in more than one index at the same time using Elastica.
I have an index products
, and an index user
.
products
contains {product_id, product_name, price}
and user
contains {product_id, user_name, date}
. Knowing that the product_id
in both of them is the same, in products
each products_id
is unique but in user
they're not as a user can buy the same product multiple times.
Anyway, I want to automatically get the price of a product from the products
index while searching through the user
index.
I know that we can search over multiple indexes like so (correct me if I'm wrong) :
$search = new \Elastica\Search($client);
$search->addIndex('users')
->addType('user')
->addIndex('products')
->addType('product');
But the problem is, when I write an aggregation on the products_id
for example and then create a new query with some filters :
$products_agg = new \Elastica\Aggregation\Terms('products_id');
$products_agg->setField('products_id')->setSize(0);
$query = new \Elastica\Query();
$query->addAggregation($products_agg);
$query->setQuery($bool);
$search->setQuery($query);
How does elastica know in which index to search? How can I link this products_id
to the other index?