{"action":"created","issue":{"url":"https://api.github.com/repos/elasticsearch/elasticsearch/issues/8134","labels_url":"https://api.github.com/repos/elasticsearch/elasticsearch/issues/8134/labels{/name}","comments_url":"https://api.github.com/repos/elasticsearch/elasticsearch/issues/8134/comments","events_url":"https://api.github.com/repos/elasticsearch/elasticsearch/issues/8134/events","html_url":"https://github.com/elasticsearch/elasticsearch/issues/8134","id":46093445,"number":8134,"title":"Refactor parent/child to not be Lucene queries","user":{"login":"jpountz","id":299848,"avatar_url":"https://avatars.githubusercontent.com/u/299848?v=3","gravatar_id":"","url":"https://api.github.com/users/jpountz","html_url":"https://github.com/jpountz","followers_url":"https://api.github.com/users/jpountz/followers","following_url":"https://api.github.com/users/jpountz/following{/other_user}","gists_url":"https://api.github.com/users/jpountz/gists{/gist_id}","starred_url":"https://api.github.com/users/jpountz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpountz/subscriptions","organizations_url":"https://api.github.com/users/jpountz/orgs","repos_url":"https://api.github.com/users/jpountz/repos","events_url":"https://api.github.com/users/jpountz/events{/privacy}","received_events_url":"https://api.github.com/users/jpountz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elasticsearch/elasticsearch/labels/discuss","name":"discuss","color":"fbca04"},{"url":"https://api.github.com/repos/elasticsearch/elasticsearch/labels/high%20hanging%20fruit","name":"high hanging fruit","color":"009800"},{"url":"https://api.github.com/repos/elasticsearch/elasticsearch/labels/PITA","name":"PITA","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-10-17T12:24:00Z","updated_at":"2015-02-13T08:51:47Z","closed_at":null,"body":"Parent/child queries have a non-desirable property: given a parent/child query Q, updating a document in segment A might change the set of matching document in another segment B.\r\n\r\nThis is an issue because it means that parent/child queries and filters cannot be cached per segment, so we had to add [logic](https://github.com/elasticsearch/elasticsearch/pull/4774) to make sure these queries don't get cached, either directly or as part of a cached parent filter (eg. under a cached `bool` filter). The propagation logic can be a bit [fragile](https://github.com/elasticsearch/elasticsearch/pull/7685) so I think we should work on a better fix.\r\n\r\nOne idea could be to change the abstraction we have to match document from a single Lucene query to something that could perform several Lucene queries. For instance in the case of `has_child`, we could have a first query that would collect parent ids and then build a new query based on these ids. This is the same execution logic, but each query on its own would solely depend on data that is stored in the current segment, so they would be cacheable (even though it might not a good idea to cache them)."},"comment":{"url":"https://api.github.com/repos/elasticsearch/elasticsearch/issues/comments/74222649","html_url":"https://github.com/elasticsearch/elasticsearch/issues/8134#issuecomment-74222649","issue_url":"https://api.github.com/repos/elasticsearch/elasticsearch/issues/8134","id":74222649,"user":{"login":"jpountz","id":299848,"avatar_url":"https://avatars.githubusercontent.com/u/299848?v=3","gravatar_id":"","url":"https://api.github.com/users/jpountz","html_url":"https://github.com/jpountz","followers_url":"https://api.github.com/users/jpountz/followers","following_url":"https://api.github.com/users/jpountz/following{/other_user}","gists_url":"https://api.github.com/users/jpountz/gists{/gist_id}","starred_url":"https://api.github.com/users/jpountz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpountz/subscriptions","organizations_url":"https://api.github.com/users/jpountz/orgs","repos_url":"https://api.github.com/users/jpountz/repos","events_url":"https://api.github.com/users/jpountz/events{/privacy}","received_events_url":"https://api.github.com/users/jpountz/received_events","type":"User","site_admin":false},"created_at":"2015-02-13T08:51:47Z","updated_at":"2015-02-13T08:51:47Z","body":"I tried to think more about it and essentially:\r\n 1. the current design has the issue that queries are not cacheable per segment because whether a document matches a document depends on what happens in other segments as well\r\n 2. as a work-around, we could run the first phase (collecting ids) in the query parser and then return a query for the second phase (which would essentially be a fielddata terms filter with scores for each term). However this query would be specific to a given index searcher and it would not work for things that want to keep queries alive for a long time like filtered aliases or the percolator\r\n 3. using a different abstraction is tempting, but then you could only use parent/child queries as top-level queries (ie. no more nesting in boolean queries)"}}