Boosting based on child documents value

Hi all,
I just started to use ElasticSearch and I found parent/child document
feature very powerful over other search server options.

I can successfully create parent/child docs relation with below sample
and I can query over existence of a child document value.
But I want to boost parent document based on a child item value.

For example I want to boost "product" by viewcount value from child
object. As I understand I need to use custom_score but I couldn't find
an example for this kind of requirement.

thanks

curl -XDELETE 'http://localhost:9200/test'
curl -XPUT 'http://localhost:9200/test/product/1' -d
'{"name" :"product1", "price":10}'
curl -XPUT 'http://localhost:9200/test/product/2' -d '{"name" :
"product2", "price":11}'
curl -XPUT 'http://localhost:9200/test/product/3' -d
'{"name" :"product3", "price":8 }'

curl -XPUT 'http://localhost:9200/test/product_extra/_mapping' -d
'{"child" : { "_parent" : {"type" : "product" } }}'
curl -XPUT 'http://localhost:9200/test/product_extra/1?parent=1' -d
'{ "tag" : "games", "viewcount" : 100 }'
curl -XPUT 'http://localhost:9200/test/product_extra/2?parent=2' -d
'{ "tag" : "office", "viewcount" : 10 }'

curl -XGET 'http://localhost:9200/test/product/_search?
pretty=1&search_type=dfs_query_then_fetch' -d '{
"query":{
"bool":{
"must":[
{
"has_child":{
"type":"product_extra",
"query":{
"query_string":{
"query":"games"
}
}
}
}
]
}
}
}'

any help or resource would be appreciated. Can anyone help me on this?

Thanks

On Jul 13, 2011, at 4:56 PM, Cengiz Han cengiz@cengizhan.com wrote:

Hi all,
I just started to use Elasticsearch and I found parent/child document
feature very powerful over other search server options.

I can successfully create parent/child docs relation with below sample
and I can query over existence of a child document value.
But I want to boost parent document based on a child item value.

For example I want to boost "product" by viewcount value from child
object. As I understand I need to use custom_score but I couldn't find
an example for this kind of requirement.

thanks

curl -XDELETE 'http://localhost:9200/test'
curl -XPUT 'http://localhost:9200/test/product/1' -d
'{"name" :"product1", "price":10}'
curl -XPUT 'http://localhost:9200/test/product/2' -d '{"name" :
"product2", "price":11}'
curl -XPUT 'http://localhost:9200/test/product/3' -d
'{"name" :"product3", "price":8 }'

curl -XPUT 'http://localhost:9200/test/product_extra/_mapping' -d
'{"child" : { "_parent" : {"type" : "product" } }}'
curl -XPUT 'http://localhost:9200/test/product_extra/1?parent=1' -d
'{ "tag" : "games", "viewcount" : 100 }'
curl -XPUT 'http://localhost:9200/test/product_extra/2?parent=2' -d
'{ "tag" : "office", "viewcount" : 10 }'

curl -XGET 'http://localhost:9200/test/product/_search?
pretty=1&search_type=dfs_query_then_fetch' -d '{
"query":{
"bool":{
"must":[
{
"has_child":{
"type":"product_extra",
"query":{
"query_string":{
"query":"games"
}
}
}
}
]
}
}
}'

The only option you have is using the top_children option, which has a custom score query within it running on the child documents.

The nested support in master (upcoming 0.17) makes it simpler and more performant (but requires the nested docs to be part of the json indexed).

On Friday, July 15, 2011 at 8:36 AM, Cengiz Han wrote:

any help or resource would be appreciated. Can anyone help me on this?

Thanks

On Jul 13, 2011, at 4:56 PM, Cengiz Han <cengiz@cengizhan.com (mailto:cengiz@cengizhan.com)> wrote:

Hi all,
I just started to use Elasticsearch and I found parent/child document
feature very powerful over other search server options.

I can successfully create parent/child docs relation with below sample
and I can query over existence of a child document value.
But I want to boost parent document based on a child item value.

For example I want to boost "product" by viewcount value from child
object. As I understand I need to use custom_score but I couldn't find
an example for this kind of requirement.

thanks

curl -XDELETE 'http://localhost:9200/test'
curl -XPUT 'http://localhost:9200/test/product/1' -d
'{"name" :"product1", "price":10}'
curl -XPUT 'http://localhost:9200/test/product/2' -d '{"name" :
"product2", "price":11}'
curl -XPUT 'http://localhost:9200/test/product/3' -d
'{"name" :"product3", "price":8 }'

curl -XPUT 'http://localhost:9200/test/product_extra/_mapping' -d
'{"child" : { "_parent" : {"type" : "product" } }}'
curl -XPUT 'http://localhost:9200/test/product_extra/1?parent=1' -d
'{ "tag" : "games", "viewcount" : 100 }'
curl -XPUT 'http://localhost:9200/test/product_extra/2?parent=2' -d
'{ "tag" : "office", "viewcount" : 10 }'

curl -XGET 'http://localhost:9200/test/product/_search?
pretty=1&search_type=dfs_query_then_fetch' -d '{
"query":{
"bool":{
"must":[
{
"has_child":{
""type":"product_extra",
"query":{
"query_string":{
""query":"games"
}
}
}
}
]
}
}
}'