sherlock
sherlock copied to clipboard
How to add a child document to a parent document
I can't figure out how to add a child document, as in one defined with a _parent mapping
Manually I would do:
curl -XPOST localhost:9200/shares/comment/1?parent=2 -d '{
"text": "test comment"
}'
Yeah, parent/child isn't very well supported by Sherlock right now. I think you can fake it by doing this:
$doc = $sherlock->document()->index('shares')
->type('comment')
->document(array("text" => "test comment"), "1?parent=2");
Internally, the ID parameter of a document is simply appended to the URI, so this little hack should work until proper functionality is built (probably while the whole indexing class is refactored, see #34 )
Sorry =(
Could be useful when indexing pages. When a page is set offline, it's deleted from the index, but I also need its children to be removed from the index. Trying to figure out how best to do this.
I tried using the "1?parent=2" but then my delete request wouldn't find my document anymore, when I remove the parent parameter, it finds the document. So somehow when you define a parent, the document won't be found by id.
Did you replace the 1 with the ID of your new document? — chad
On Tue, Apr 16, 2013 at 6:12 AM, Kenny Debrauwer [email protected] wrote:
I tried using the "1?parent=2" but then my delete request wouldn't find my document anymore, when I remove the parent parameter, it finds the document. So somehow when you define a parent, the document won't be found by id.
Reply to this email directly or view it on GitHub: https://github.com/polyfractal/sherlock/issues/35#issuecomment-16436602
Yes, I checked my index with the head plugin and the document ID's were identical
Hm, the parent field is definitely necessary for child deletions. Without the parent field, the ID is used as the hash and the delete request could be sent to the incorrect shard.
It's either a syntax problem with the generated JSON (can you get a debug print out of the request URI?), or potentially a problem with your parent/child mapping.
At the moment I created my own parent/ancestors field and worked with that to find and delete child documents. See method starting from line 202 here : https://github.com/Kunstmaan/KunstmaanNodeSearchBundle/blob/master/Configuration/NodeSearchConfiguration.php
I'll give it another go like suggested above and I'll post my findings here.
Ah, I see. That may be the best solution for the time being, I deliberately left parent/child support in a spotty condition because I wanted to fill out the core functionality first (same reason nested and geo support is pretty poor across the library).