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

Add a has_parent query #792

Closed
merrellb opened this issue Mar 18, 2011 · 14 comments
Closed

Add a has_parent query #792

merrellb opened this issue Mar 18, 2011 · 14 comments

Comments

@merrellb
Copy link

Would return children objects similar to how the has_child query returns parent objects.

@dstendardi
Copy link

+1 this feature would be very useful !

@nhuray
Copy link
Contributor

nhuray commented Mar 10, 2012

@hlian

I've just tested it and It works like a charm !

It's a really nice feature, congratulations.

@dstendardi
Copy link

Great feature. thank you hlian !

@fcheung
Copy link

fcheung commented Mar 29, 2012

This looks really useful, thanks. Is this ready for prime time or still a work in progress? Have you approached Shay about getting this merged in?

@hlian
Copy link

hlian commented Apr 2, 2012

Thank you for the kind words, guys. @kevingessner and I are crazy busy right now getting a release out and @flxs is doing a lot of the hard work to get the stuff merge-ready, so I'd like to bless his branch as the place for has_parent development to happen. I'd be happy to answer questions about the implementation, but I'm afraid either of us can't commit to writing more code for this feature or to spending time shepherding it into trunk.

@jmchambers
Copy link

I just tried @flxs's branch and can confirm that this filter is officially awesome :)

It has allowed me to redesign my un-scalable app (relying on frequent and expensive re-indexing of docs + nested docs) to a fully scalable one using parent & child docs instead.

Thanks to @hilan, @kevingessner and @flxs for getting it working - hope it finds its way into trunk soon.

BTW, if there are any other java-illiterates reading this thread who, like me, can't figure out how to get the download working, you need to make sure all dependencies are assembled in the target/lib directory by running the following (from the root folder):

$ mvn prepare-package -DskipTests

and then run ES with:

$ ES_CLASSPATH="target/classes:target/lib/*" bin/elasticsearch -f

(from http://bit.ly/HKmckR)

Thanks again.

@r10r
Copy link

r10r commented Jun 3, 2012

I've added a gist for testing the has_parent search filter from commandline using curl against the json API: https://gist.github.com/2865256.
(Just modified the has_child gist from @ToulBoy slightly https://gist.github.com/1941432)

@Vineeth-Mohan
Copy link

+1

@jmchambers
Copy link

UPDATE I've narrowed down the problem. If I create the index and add some parent and child docs, the has_parent filter doesn't work until I restart the server. However, this only works once. If I add additional child docs, or if I update the existing ones, the results of the has_parent filter don't reflect the changes. It's as if the filter is working with a stale copy of the data set - very weird...


I was wondering if someone on this thread could help me. The has_parent fork was working really nicely, but has now suddenly stopped working - which has left me thoroughly confused!

I haven't changed anything as far as I know. I downloaded and built @flxs's branch 3 months ago and it worked just fine. But when I revisited my test index today it seems to be broken. The has_child filter continues to work as normal, but has_parent seems to ignore newly indexed documents. Sometimes restarting the server will make it pick them up but mostly not.

Can anyone think why this might be? Does ES have runtime dependencies that might have been changed by system updates (I'm on Ubuntu 11.04)?

@nickhoffman
Copy link

It looks like this solves the exact problem I'm tackling right now. Any idea when it'll be ready for prime time?

@nhuray
Copy link
Contributor

nhuray commented Sep 1, 2012

Hi everyone,

I'm very interested by this filter, so I'd like to know if you consider it's ready for production or if it is still unstable.
I can help if you want to review the code and add tests if necessary.

@jmchambers : Did you fix your troubles since 2 month or do you need help to investigate the problem ?

@kimchy : Do you have any plan to integrate the has_parent filter in 0.20 ?

Cheers,

@jeremydaly
Copy link

I really need this capability.

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Sep 13, 2012
The `has_parent` filter accepts a query and a parent type. The query is executed in the parent document space, which is specified by the parent type. This filter return child documents which associated parents have matched. For the rest `has_parent` filter has the same options and works in the same manner as the `has_child` filter.

This is an experimental filter.

Filter example
###################
```
{
    "has_parent" : {
        "parent_type" : "blog"
        "query" : {
            "term" : {
                "tag" : "something"
            }
        }
    }
}
```
The `parent_type` field name can also be abbreviated to `type`.

Memory considerations
###############
With the current implementation, all _id values are loaded to memory (heap) in order to support fast lookups, so make sure there is enough mem for it.

This issue originates from issue elastic#792
martijnvg added a commit that referenced this issue Sep 13, 2012
The `has_parent` filter accepts a query and a parent type. The query is executed in the parent document space, which is specified by the parent type. This filter return child documents which associated parents have matched. For the rest `has_parent` filter has the same options and works in the same manner as the `has_child` filter.

This is an experimental filter.

Filter example
###################
```
{
    "has_parent" : {
        "parent_type" : "blog"
        "query" : {
            "term" : {
                "tag" : "something"
            }
        }
    }
}
```
The `parent_type` field name can also be abbreviated to `type`.

Memory considerations
###############
With the current implementation, all _id values are loaded to memory (heap) in order to support fast lookups, so make sure there is enough mem for it.

This issue originates from issue #792
martijnvg added a commit that referenced this issue Sep 13, 2012
The `has_parent` filter accepts a query and a parent type. The query is executed in the parent document space, which is specified by the parent type. This filter return child documents which associated parents have matched. For the rest `has_parent` filter has the same options and works in the same manner as the `has_child` filter.

This is an experimental filter.

Filter example
###################
```
{
    "has_parent" : {
        "parent_type" : "blog"
        "query" : {
            "term" : {
                "tag" : "something"
            }
        }
    }
}
```
The `parent_type` field name can also be abbreviated to `type`.

Memory considerations
###############
With the current implementation, all _id values are loaded to memory (heap) in order to support fast lookups, so make sure there is enough mem for it.

This issue originates from issue #792
@martijnvg
Copy link
Member

This has been pushed in #2243 and will be available 0.19.10

@jmchambers
Copy link

great news, thanks for getting this in the main release.

@nhuray afraid I didn't get it working, but I'll give it another try with 0.19.10, thanks for asking though.

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
The `has_parent` filter accepts a query and a parent type. The query is executed in the parent document space, which is specified by the parent type. This filter return child documents which associated parents have matched. For the rest `has_parent` filter has the same options and works in the same manner as the `has_child` filter.

This is an experimental filter.

Filter example
###################
```
{
    "has_parent" : {
        "parent_type" : "blog"
        "query" : {
            "term" : {
                "tag" : "something"
            }
        }
    }
}
```
The `parent_type` field name can also be abbreviated to `type`.

Memory considerations
###############
With the current implementation, all _id values are loaded to memory (heap) in order to support fast lookups, so make sure there is enough mem for it.

This issue originates from issue elastic#792
williamrandolph pushed a commit to williamrandolph/elasticsearch that referenced this issue Jun 4, 2020
emilykmarx pushed a commit to emilykmarx/elasticsearch that referenced this issue Dec 26, 2023
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