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

Parent is not getting set, using UpdateRequest in JavaAPI #4538

Closed
sandy6jain opened this issue Dec 23, 2013 · 7 comments
Closed

Parent is not getting set, using UpdateRequest in JavaAPI #4538

sandy6jain opened this issue Dec 23, 2013 · 7 comments
Assignees
Labels
good first issue low hanging fruit

Comments

@sandy6jain
Copy link

I found a similar bug #3444, but it is not fixed in JavaAPI with requesting using UpdateReuest.
To resolve this, "UpdateRequest.java" should have property "parent" & it should be used while generating upsertRequest. (I am using version 0.90.5)
Test with the following code :

curl -XPOST 'http://localhost:9200/123'
curl -XPOST 'http://localhost:9200/123/TableWithParent/_mapping' -d '
{"TableWithParent" : {"_parent" : { "type" : "Table1" }}}'

Inserting data using JavaAPI:

public static void main(String[] args) {
Client client = NodeBuilder.nodeBuilder().node().client();
Map<String, Object> data = new HashMap<String, Object>();
data.put("column1", "colVal1");
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index("123");
updateRequest.docAsUpsert(true);
updateRequest.routing("123");
updateRequest.parent("parentID");
updateRequest.id("123|8|627110220645727|662022187154530");
updateRequest.type("TableWithParent");
updateRequest.doc(data);
client.update(updateRequest);
}

Below query, should return parent object:
curl -XGET 'http://localhost:9200/123/TableWithParent/123|8|627110220645727|662022187154530?routing=123&pretty&fields=_parent,_source'

Thanks

@martijnvg
Copy link
Member

The UpdateRequest#parent() method should only be used to set routing if not set already via the routing setter, it doesn't set the _parent field (see the java doc).

You should set the _parent field in the index request that you can pass via UpdateRequest#doc(IndexRequest)

@sandy6jain
Copy link
Author

Thanks @martijnvg, that works 👍 but, when docAsUpsert as true & it can create new document than it should set _parent mapping field. It seems little confusing to me as parent() method in update action has different behaviour than other actions.
If you have any performance numbers of setting parent via UpdateRequest in a very high update(refresh) payload, can you please help me in that.
Thanks a lot for your response

@martijnvg
Copy link
Member

In the update request, the parent method's purpose if for routing only. I think it should be removed, to avoid confusion.

@martijnvg
Copy link
Member

I misunderstood what had to be done for this issue. The parent option should not have been removed instead the parent option shouldn't update the parent of an existing document. This was already the case as the update logic ignores the parent option (and routing option too).

The issue here is that although in normal use case the parent option is ignore and just a place holder for routing, in the case a document doesn't exist the parent option should be delegated to the upsert document.

I'll do the following changes:

  • Revert the commit on master.
  • Make sure that if parent has been set on update request that it delegates this to the parent option on upsert request or doc request if doc_as_upsert option has been set to true.

@lukens
Copy link

lukens commented Feb 27, 2015

Any timeline as to when this might get resolved?

After spending a morning trying to figure out why my has_child query wasn't working, I tracked it down to the Java API not setting the parent when inserting on an upsert.

This has left me a bit scuppered.

Any suggestions for a workaround would also be appreciated.

@martijnvg
Copy link
Member

@lukens #9612 fixes the issue. It has been targeted to 2.0, but I think it can be included in 1.x branch, which means it make it in 1.5 release.

@lukens
Copy link

lukens commented Feb 27, 2015

Thanks, I've copied in the changes to UpdateRequest and UpdateHelper from the pull request into the 1.4.4 versions of those classes, and have managed to get it working.

I believe I found an issue with the changes though, and have added a comment: https://github.com/elasticsearch/elasticsearch/pull/9612/files#r25503572

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Mar 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue low hanging fruit
Projects
None yet
Development

No branches or pull requests

4 participants