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

elasticsearch can not update active record that has a parent relation #5758

Closed
cebe opened this issue Oct 25, 2014 · 11 comments
Closed

elasticsearch can not update active record that has a parent relation #5758

cebe opened this issue Oct 25, 2014 · 11 comments

Comments

@cebe
Copy link
Member

cebe commented Oct 25, 2014

#!/bin/sh

curl -XDELETE "http://localhost:9200/bugreport"
curl -XPUT "http://localhost:9200/bugreport"
echo ""
echo "create tasks:"
curl -XPUT "http://localhost:9200/bugreport/_mapping/tasks" -d '{
"tasks": {
    "_id": {"path": "id", "index": "not_analyzed"},
    "properties": {
        "id": {"type": "string", "index": "not_analyzed"}
    }
}}'
echo ""
echo "create task_comments:"
curl -XPUT "http://localhost:9200/bugreport/_mapping/task_comments" -d '{
"task_comments": {
    "_parent": {"type": "tasks"},
    "_routing": {"required": true},
    "properties": {
        "taskId": {"type": "string", "index": "not_analyzed"},
        "message": {"type": "string"}
    }
}}'
echo ""
echo "add task record:"
curl -XPUT "http://localhost:9200/bugreport/tasks/cebe%2Ftest%2F6?op_type=create" -d '{
    "title":"test",
    "description":"test",
    "id":"cebe\/test\/6"
}'
echo ""
echo "add task_comments record:"
curl -XPUT "http://localhost:9200/bugreport/task_comments/1?op_type=create&parent=cebe%2Ftest%2F6" -d '{
    "taskId":"cebe\/test\/6",
    "authorId":"cebe",
    "message":"asdasd"
}'
echo ""
echo "update it:"
curl -XPOST "http://localhost:9200/bugreport/task_comments/_bulk" -d '
{"update":{"_id":"1","_type":"task_comments","_index":"bugreport"}}
{"doc":{"message":"as asdf","updated":"2014-10-24 21:59:18"}}

'
#{"update":{"_id":"1","_routing": "cebe\/test\/6","_type":"task_comments","_index":"bugreport"}}

output:

{"acknowledged":true}{"acknowledged":true}
create tasks:
{"acknowledged":true}
create task_comments:
{"acknowledged":true}
add task record:
{"_index":"bugreport","_type":"tasks","_id":"cebe/test/6","_version":1,"created":true}
add task_comments record:
{"_index":"bugreport","_type":"task_comments","_id":"1","_version":1,"created":true}
update it:
{"error":"NullPointerException[null]","status":500}
@cebe
Copy link
Member Author

cebe commented Oct 25, 2014

simple updates should not go through bulk api.

@cebe
Copy link
Member Author

cebe commented Oct 25, 2014

same for delete, do not use bulk api.

@ghost
Copy link

ghost commented Oct 31, 2014

I'm experiencing the same problem. Thanks for sharing!

@cebe
Copy link
Member Author

cebe commented Nov 17, 2014

@cebe
Copy link
Member Author

cebe commented Nov 30, 2014

related to: elastic/elasticsearch#8068 could be implemented automatically this way.

@cebe
Copy link
Member Author

cebe commented Nov 30, 2014

reported this case to improve the error message: elastic/elasticsearch#8714

@cebe cebe closed this as completed in 19224e7 Nov 30, 2014
@cebe
Copy link
Member Author

cebe commented Nov 30, 2014

@mortenzeppelin should work now, you can pass custom options to the update() and delete() method:

$comment->update(true, null, ['routing' => $task->id]

@ghost
Copy link

ghost commented Dec 1, 2014

Hi @cebe
I found that I could also update children with "_parent" : (same as routing).
However, initially I thought the child element as an independent entity, but after reading http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/
I realised the necessity for the parent ID.

@cebe
Copy link
Member Author

cebe commented Dec 1, 2014

I found that I could also update children with "_parent" : (same as routing).

You mean sending _parent within the request body/among the attributes?

@ghost
Copy link

ghost commented Dec 2, 2014

To be honest it is been a while since I worked on this. And looking at my test script I see that I did not get bulk update to work, but it should be possible like this - which is equivalent to _routing.

curl -XPOST "http://localhost:9200/bugreport/task_comments/_bulk" -d '
{"update":{"_id":"1"}}
{"doc": {"_parent": "cebe/test/6", "message":"as asdf","updated":"2014-10-24 21:59:18"}, "doc_as_upsert": True}
'

("doc_as_upsert": True) added to only update parts of document.

@cebe
Copy link
Member Author

cebe commented Dec 2, 2014

Okay, thanks. Will consider this when working on the interface for direct support of parent-child relations.

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

No branches or pull requests

1 participant