Search on only parent documents?

This might be a simple question, and if so I apologize, but I'm not sure
how to go about this.

How would I execute a query against only top-level documents? I have an
index of documents, some have child documents, but I want to exclude the
children from the query.

Thanks!

Hi Shane,

If you have them all in one type, you can search in that type. Like:

curl -XPOST localhost:9200/myindex/mytype/_search

On Wednesday, August 8, 2012 10:06:53 PM UTC+2, shane wrote:

This might be a simple question, and if so I apologize, but I'm not sure
how to go about this.

How would I execute a query against only top-level documents? I have an
index of documents, some have child documents, but I want to exclude the
children from the query.

Thanks!

There's a filter for this:

Does this help? I haven't used parent-child relations in ES myself.

Den onsdagen den 8:e augusti 2012 kl. 22:06:53 UTC+2 skrev shane:

This might be a simple question, and if so I apologize, but I'm not sure
how to go about this.

How would I execute a query against only top-level documents? I have an
index of documents, some have child documents, but I want to exclude the
children from the query.

Thanks!

Hi olof,

I did see that, but it seems like that only controls whether or not
results have children. What I want to do is match against all top-
level docs (regardless of existence or number of children), but not
match against any children.

Shane

On Aug 9, 2012, at 12:46 AM, olof wrote:

There's a filter for this:
http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html

Does this help? I haven't used parent-child relations in ES myself.

Den onsdagen den 8:e augusti 2012 kl. 22:06:53 UTC+2 skrev shane:
This might be a simple question, and if so I apologize, but I'm not
sure how to go about this.

How would I execute a query against only top-level documents? I have
an index of documents, some have child documents, but I want to
exclude the children from the query.

Thanks!

Typically, parent and child documents have different types. If this is your
case, all you need to do is to limit your search to the parent type. If for
some reason you used the same type, you can find all records that have no
parents specified by searching for -_parent:* like this:

curl "http://localhost:9200/your-index/your-type/_search?q=-_parent:*"

This will return all nodes that have empty _parent field.

Igor

On Thursday, August 9, 2012 1:24:11 PM UTC-4, shane wrote:

Hi olof,

I did see that, but it seems like that only controls whether or not
results have children. What I want to do is match against all top-
level docs (regardless of existence or number of children), but not
match against any children.

Shane

On Aug 9, 2012, at 12:46 AM, olof wrote:

There's a filter for this:

http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html

Does this help? I haven't used parent-child relations in ES myself.

Den onsdagen den 8:e augusti 2012 kl. 22:06:53 UTC+2 skrev shane:
This might be a simple question, and if so I apologize, but I'm not
sure how to go about this.

How would I execute a query against only top-level documents? I have
an index of documents, some have child documents, but I want to
exclude the children from the query.

Thanks!

Aha, thanks Igor. Yes, I do happen to be using the same type for
parent and child. In this case, it's an index of products, and
children are variations of those products.

Shane

On Aug 9, 2012, at 12:41 PM, Igor Motov wrote:

Typically, parent and child documents have different types. If this
is your case, all you need to do is to limit your search to the
parent type. If for some reason you used the same type, you can find
all records that have no parents specified by searching for -
_parent:* like this:

curl "http://localhost:9200/your-index/your-type/_search?q=-_parent:*"

This will return all nodes that have empty _parent field.

Igor

On Thursday, August 9, 2012 1:24:11 PM UTC-4, shane wrote:
Hi olof,

I did see that, but it seems like that only controls whether or not
results have children. What I want to do is match against all top-
level docs (regardless of existence or number of children), but not
match against any children.

Shane

On Aug 9, 2012, at 12:46 AM, olof wrote:

There's a filter for this:
http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html

Does this help? I haven't used parent-child relations in ES myself.

Den onsdagen den 8:e augusti 2012 kl. 22:06:53 UTC+2 skrev shane:
This might be a simple question, and if so I apologize, but I'm not
sure how to go about this.

How would I execute a query against only top-level documents? I have
an index of documents, some have child documents, but I want to
exclude the children from the query.

Thanks!