Parent/child "where parent exists" query


(Thomas) #1

Hi,

I have been working with a parent child schema creation and I was wondering if there is a way to perform a search in children documents with the query "where parent exists" and get only those documents.

I can index children documents and there is no mandatory to have parent document. Therefore, I want only to get the children who have a parent document.

Is this functionality possible? How is possible to perform such query? I work with latest version 1.0.0.RC1

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/69af02d6-a717-42b4-956a-8f76c5ebb2e9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Adrien Grand) #2

Hi Thomas,

Using a has_child[1] filter on top of a match_all[2] filter should work.

[1]
http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/query-dsl-has-parent-filter.html
[2]
http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/query-dsl-match-all-query.html

On Thu, Jan 23, 2014 at 7:25 PM, Thomas thomas.bolis@gmail.com wrote:

Hi,

I have been working with a parent child schema creation and I was
wondering if there is a way to perform a search in children documents with
the query "where parent exists" and get only those documents.

I can index children documents and there is no mandatory to have parent
document. Therefore, I want only to get the children who have a parent
document.

Is this functionality possible? How is possible to perform such query? I
work with latest version 1.0.0.RC1

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/69af02d6-a717-42b4-956a-8f76c5ebb2e9%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
Adrien Grand

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7ruw7nm6dCPwNF%2B6GU7A3iocRXKZbY%3DQrdoCxzMhy1fQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Thomas) #3

Hi Adrien and thanks for the reply,

This sounds like what I was looking for :slight_smile: Will investigate it

Thanks
Thomas

On Thursday, 23 January 2014 20:25:01 UTC+2, Thomas wrote:

Hi,

I have been working with a parent child schema creation and I was
wondering if there is a way to perform a search in children documents with
the query "where parent exists" and get only those documents.

I can index children documents and there is no mandatory to have parent
document. Therefore, I want only to get the children who have a parent
document.

Is this functionality possible? How is possible to perform such query? I
work with latest version 1.0.0.RC1

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3bda84b6-a01c-4123-a875-05d7b23e9389%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Thomas) #4

Hi,

I have two questions with regards this feature

  1. I have been reading the documentation and at some point it described
    that all _ids are loaded into memory:

all _id values are loaded to memory (heap) in order to support fast lookups

This means that only the parent _ids that match correct? Not all the _ids
of the parent/child relationship

  1. Is it possible to perform an aggregation and take some values from the
    parent document and some from the child document? for example take some
    information from the parent document (e.g. city) and some information from
    the child document (e.g. for car model= BMW) and do some counts? and
    present them all together?

e.g.

{

"parentDoc":{

"properties": {

"city":{

"type": "string",

"index": "not_analyzed"

}

}

}

}

{

"childDoc":{

"properties": {

"carModel":{

"type": "string",

"index": "not_analyzed"

}

}

}

}

Aggregate child documents per child Document where parent exists (because i
have childDocuments without parent info and i do not want to take those)
per city and carModel. Below is an idea of what I'm trying to do

curl -XGET 'localhost:9200/delivery_logs_pc_idx/childDoc/_search?pretty' -d
'{
"query": {
"match_all":{}
},
"aggregations" : {
"myFilter" : {
"filter" : {
{
"has_parent" : {
"type" : "deliveryLog",
"query": {"match_all":{}}
}
}
},
"aggregations" : {
"preferrence" : { "terms" : { "script" : "
doc.parent.city.value + doc.child.carModel.value", "size":100 } }
}
}
},
"size":0
}'

Is there an alternative way of achieving that?

Thank you

On Thursday, 23 January 2014 20:25:01 UTC+2, Thomas wrote:

Hi,

I have been working with a parent child schema creation and I was
wondering if there is a way to perform a search in children documents with
the query "where parent exists" and get only those documents.

I can index children documents and there is no mandatory to have parent
document. Therefore, I want only to get the children who have a parent
document.

Is this functionality possible? How is possible to perform such query? I
work with latest version 1.0.0.RC1

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/05e42115-b73f-40fe-81ef-332ca0ab75b1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #5