barseghyanartur / graphene-elastic

Graphene Elasticsearch/OpenSearch (DSL) integration
https://pypi.org/project/graphene-elastic/
71 stars 17 forks source link

How to use connection between indices #42

Closed datavistics closed 4 years ago

datavistics commented 4 years ago

I looked in the documentation and couldnt find anything. Say I have some indices defined like this

class Student(Document):
    name = Text()
    teacher = Text()

class Teachers(Document):
    name = Text()

If the teacher field is the Teacher id: How can I create a connection between the student and the teacher?

barseghyanartur commented 4 years ago

@datavistics:

On the Elastic part, if you want to search, you should carefully think of how do you want to structure your data. In that case you should index your data as follows:

class Student(Document):
    name = Text()
    teacher = Nested(...)  # Replace with inner doc as shown in the documentation link below

See official docs.

However, nested queries are not yet implemented in this library in a generic way. For your that should involve some custom code, instead of generic declarative approach (which is strictly followed in all implemented features). Basically, you should implement a custom search tailored for your needs and use it as desired.

datavistics commented 4 years ago

Is there a way to use a connection field like in the graphene docs? https://docs.graphene-python.org/en/latest/relay/connection/

barseghyanartur commented 4 years ago

I haven't finalised that part, because it's not how it shall be done in Elasticsearch.