Elastic search complex query

So, let us say I have 2 indices users and products.

Within users I have the following format:
users:
{
uid:"00001",
name:"Hash",
country:"US"
},

Within the products I have the following format:

product:
{
productname: "Shoes",
.
.
.
uid:"0001"
}

My question is, how I can link these 2 indices and join its data together? like in MySQL I would do the following:

SELECT * FROM users u JOIN products p ON u.uid = p.uid;

Is there anything similar in Elasticsearch query? please help!

Have a look at the approach recommended in this thread. Elasticsearch does not support joins so this is generally does by enriching at index time rather than joining at query time.

Ok, got the point behind the enricher, but the thing is the enricher is one time only, i.e. if an already existing product let's say has the userinfo and then that userinfo got updated, the product won't get updated !

e.g

users:
{
"uid": "1",
"name": "shop1"
}

products index after enriching:

{
"productname": "shoes",
"uid: "1",
"user": {
   "uid": "1",
    "name": "shop1"
 }
}

now if I updated name of shop1 to shop2 in users index then it won't get updated in products index !

@Christian_Dahlqvist

@Christian_Dahlqvist tried enriching on GET request, but couldn't, would like to have something like that if possible !

GET /products/_search?pipeline=TEST_MAP_USERS_PRODUCTS
{
  "query": {
    "match": {
      "uid": "76KQRuPLXhcPLxKX4m1gOxnTI5U2"
    }
  }
}

That does not exist. Enrichment need to be done at index time.

Got that, but after some googling I got that I need to reindex every time I update the shopname like I said above for example! Is there a better alternative?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.