Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a child document to a parent document #35

Open
chadkouse opened this issue Apr 10, 2013 · 8 comments
Open

How to add a child document to a parent document #35

chadkouse opened this issue Apr 10, 2013 · 8 comments

Comments

@chadkouse
Copy link

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"
}'
@polyfractal
Copy link
Owner

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 =(

@Mopster
Copy link
Contributor

Mopster commented Apr 16, 2013

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.

@Mopster
Copy link
Contributor

Mopster commented Apr 16, 2013

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.

@chadkouse
Copy link
Author

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:
#35 (comment)

@Mopster
Copy link
Contributor

Mopster commented Apr 16, 2013

Yes, I checked my index with the head plugin and the document ID's were identical

@polyfractal
Copy link
Owner

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.

@Mopster
Copy link
Contributor

Mopster commented Apr 16, 2013

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.

@polyfractal
Copy link
Owner

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants