Has_child and matching children

Hello everybody

I'm wondering if there is a way of getting some information about the
children (a list of ids would be ok) matching the has_child query along
with the parent object.

Example here:

I've got a parent object:

curl -XPUT 'localhost:9200/products' -d '
{
"mappings" : {
"Root" : {
"dynamic" : false,
"properties" : {
"id" : { "type" : "integer" }
}
},
"Child" : {
"_parent" : { "type" : "Root" },
"dynamic" : false,
"properties" : {
"id" : { "type" : "integer" },
"name" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
'

And I have a query like this:

curl -X POST 'localhost:9200/products/_search?pretty=true' -d '
{
"query" : {
"match_all" : {}
},
"filter" : {
"has_child" : {
"type" : "Child",
"query" : {
"prefix" : { "name" : "AS" }
}
}
}
}
'

As a result I get parent documents that contains children which name starts
with 'AS'. So is there a way of getting the information about which
children matched the filter?

Thanks in advance
Paweł

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

At the moment something like this is only possible by doing subsequent
request(s).
For each parent documents that you want to know the top matching child docs
for you can execute the following request:
curl -X POST 'localhost:9200/products/Child/_search?pretty=true' -d '
{
"query" : {
"match_all" : {}
},
"filter" : {
"bool" : {
"must" : [
{
"term" : {"_parent" : "THE_PARENT_ID"}
},
{
"prefix" : { "name" : "AS" }
}
]
}
}
}
'

In order to optimise the above approach you can combine the search requests
into one request use the multi search api:
http://www.elasticsearch.org/guide/reference/api/multi-search.html

Hope it helps.

Martijn

On 18 March 2013 15:40, Paweł Młynarczyk zwarios@gmail.com wrote:

Hello everybody

I'm wondering if there is a way of getting some information about the
children (a list of ids would be ok) matching the has_child query along
with the parent object.

Example here:

I've got a parent object:

curl -XPUT 'localhost:9200/products' -d '
{
"mappings" : {
"Root" : {
"dynamic" : false,
"properties" : {
"id" : { "type" : "integer" }
}
},
"Child" : {
"_parent" : { "type" : "Root" },
"dynamic" : false,
"properties" : {
"id" : { "type" : "integer" },
"name" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
'

And I have a query like this:

curl -X POST 'localhost:9200/products/_search?pretty=true' -d '
{
"query" : {
"match_all" : {}
},
"filter" : {
"has_child" : {
"type" : "Child",
"query" : {
"prefix" : { "name" : "AS" }
}
}
}
}
'

As a result I get parent documents that contains children which name
starts with 'AS'. So is there a way of getting the information about which
children matched the filter?

Thanks in advance
Paweł

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
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.
For more options, visit https://groups.google.com/groups/opt_out.