Closed jaddison closed 6 years ago
You can have a look in the examples
directory where there is a complex model using parent/child via the join field.
Hope this helps!
I was just going to say that I found https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/parent_child.py
- I think it would be good to have a mention about this in the docs, however.
It is mentioned in the readme and at the top of the documentation: http://elasticsearch-dsl.readthedocs.io/en/latest/#examples
If there is more places where we could mention it i would be very happy for the suggestion. Thanks!
@HonzaKral Yes, I did notice that link - but I was searching the docs for the keyword join
and nothing came up.
Anyhow, sorry for the noise.
@HonzaKral, sorry to bother you again on this!
In looking at the parent/child example, it doesn't look like it sets the mapping fields for the Question
and Answer
documents into the index - only that of the 'abstract' base Post
document: https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/parent_child.py#L174
Can fields from two different documents be set in the same index? The example doesn't seem to cover this.
@jaddison yes, fields from two document classes can be defined on the same index and the example does use this approach since Question
and Answer
extend Post
and don't override class Index
the mappings will be merged and the base
template then contain fields from both classes.
@HonzaKral I think I see now: the meta Index
class on a parent (ie. Post
) is shared amongst all subclasses that don't have their own Index
meta class in place.
Meaning, subclass field definitions 'get applied' to the Post
's Index
meta class, correct?
Regardless, thank you for pointing me in the right direction.
I've been using the low level
elasticsearch-py
for a while now - dealing with complexdict
-type query layouts, etc. I'm interested in moving towards using this DSL library.At the same time, I'm looking at upgrading from ES 5.x to 6.x - however, this means I need to switch my mappings to be 'typeless' (a single mapping per index) and maintain a parent/child relationship. My understanding is that I need to use the underlying
join
field type.So, I currently have
Business
andActivity
type mappings (Business
is the parent ofActivity
) in a single index. With ES 5.x, I would obviously just create an ES-DSLDocument
for each:BusinessDocument
andActivityDocument
, and set up things with_parent
and whatnot, I assume.How would this work with ES 6.x
join
fields though (given that a single mapping exists for an index)? I don't think I'd want a combinedBusinessActivityDocument
, because I would still want to doBusinessDocument.search().filter(...)
separately fromActivityDocument.search().filter(...)
and have relevant fields?Am I missing something? Thanks!