Elasticsearch get all parents and children - elasticsearch

I have an Elastic Search mapping with parent and child documents. It can be one-to-many but I have only created one-to-one relationship between a parent and child. Reason for this relationship instead of nested documents is that children are updated frequently and I can avoid touching parent documents everytime. This would avoid creating deleted documents of parent doc type which is taking 70% more space than required before merge happens.
Now I have a query which returns a list of parent documents. But I also want to retrieve all children for that parent list.
Is it possible to get all parents and associated children with the same query instead of running a separate query to get children of each parent?

Related

GraphQl Java- Update fields in parent object once grand child object fields are resolved

I'm new to Graphql. I'm aware that Graphql resolves query in breadth first approach. But is there a way to update/refresh values in parent fields once the grand child object(or any object in further depth) resolves its values. Or can i add a transformation layer which will update the values of certain fields before sending the response to the client?

ElasticSearch - Multiple types sharing the same child type

I'm looking for some help with ElasticSearch involving multiple "parent" types sharing the same "child" type.
As a trivial example, let's say I have two parent types:
blogEntry
status
I'd like to have a single "comment" type which is a child of both "blogEntry" and "status", since users can comment on both blog entries and users' status updates.
Is this actually possible in ES?
Or, am I looking at this problem in the wrong way? Does parent-child make no sense here, and instead would I want to use nested objects?
Thanks!
This is not possible at the moment:
The parent child mapping does not allow to specify multiple parents
Lets say if you have 2 parents which are routed to different shards,
which shard will the child document be routed to?
You could instead have one child as nested document to the parent and the more frequently changing one as an actual child referencing the parent type.

Setting ID on child properties with EFBulkInsert

So im using EFBulkInsert https://efbulkinsert.codeplex.com/
The problem is I have child objects I need to set the ID of the inserted parent objects.
Previously after inserting the parents objects I've tried to rely on the context to return the id's and set them on the child objects - then use EFBulkInsert to insert the child objects - every now and then the context gets confused even after recreating the context and I get the wrong id on the child objects.
Does anyone have a good pattern / strategy for setting the parent id on the child object I should mention i'm doing this for a batch of 1000 parent objects. So I don't particularly want to get the id's from the database after SaveChanges for the parent object unless it's performant.
The best idea I have is to add two temporary columns, firtst to hold an original Id, and second to hold parentId. After bulk insert update proper columns. This method requires privilages to modify the table.
I had a similar problem when I couldn't modify database, so I set AutoDetectChangesEnabled and ValidateOnSaveEnabled to false, but results were not very satisfied.

Doctrine PHPCR #Children & #Child

I started learning PHPCR with doctrine in Symfony-CMF, and I have a question.
Is that possible to have #Children and #Child on 2 differents attributes of the same document ?
According to the doc...
The annotated instance variable will be populated with Documents directly below the instance variables document class in the document hierarchy.
I think that there should be only one #Children or #Child per document. But how to manage forms if there's different documents into the same attribute ? It's not clear for me the usage of this. Should I choose one attribute whith #Children & #ReferenceOne / #ReferenceMany on the others ?
PHPCR is a tree, every node is located under its parent. For the parent, that is a child node. When using #Child, you adress one specific child with a field. Using #Children, you map all child documents and the member variable having this mapping contains a collection. note that there is a middle ground: you can specify to filter #Children by a naming pattern of the children.
indeed you can end up with the same child in #Child and #Children - we recommend to not inline the editing of an unfiltered children collection, but make that links. if you have a filtered children collection and a separate child, things can work out nicely.
references are cross-links not following the tree hierarchy. they are less efficient than parent-child relations. you should only use those for secondary relations, but keep your primary content structured in the tree.

How to GET the child record from parent child in ElasticSearch?

I simply would like to GET the child record directly after inserting both the Parent and the Child. Must I do a search query to just get the child or can I just do a standard GET with just the index, type, id of the child record?
thanks
Yes, you can just do a standard GET on the child index, type and id, but as user983022 mentioned, you'll need to use the parent_id as the routing parameter in your request, otherwise ES will likely look on the wrong shard for the child document.
For more information on parent/child and routing, read http://www.elasticsearch.org/blog/customizing-your-document-routing/ and http://www.elasticsearch.org/guide/reference/api/get/ mentions using the routing parameter in GET requests.
Answer: you need to add the routing parameter with the parent ID to retrieve the child record.

Resources