Kaushal Prajapati
Kaushal Prajapati

Reputation: 73

How do I join two ElasticSearch indices using elasticsearch-dsl-py?

Two indices documents as below:

class First(Document):

    class Index:
       name  = 'first'
       
   case_id = Keyword()
   name = Text()
   
class Second(Document):

    class Index:
       name  = 'second'
       
   case_id = Keyword()
   status = Text()

I just want to execute a query like below in SQL format

select * from first as f, second as s where s.case_id = f.case_id or s.status = 'xyz'

How can I do it using elastic search dsl query?

Upvotes: 0

Views: 588

Answers (1)

Sahil Gupta
Sahil Gupta

Reputation: 2166

  1. Elastic Search doesn't support joins between indexes

    Reason: Elastic Search is not relational and denormalized data should be stored here.

    Excerpt from elastic Doc below :

Performing full SQL-style joins in a distributed system like Elasticsearch is prohibitively expensive. Instead, Elasticsearch offers two forms of join which are designed to scale horizontally.

  1. Use either nesting or parent/child mapping to store your data, based on the use case.

    Nesting: If cardinality of nested doc is very low and indexes are read intensive

    Parent/child: If cardinality of child is very high than parent and parent/child needs to be updated frequently

Upvotes: 1

Related Questions