Querying both parent as child document fields

Hello,

I'm struggling a bit to write a query that would query fields on a parent
document and the fields on a child document.

first thought, my mapping:
I have documents of type 'resource' (these are the parent docs)
which have a couple of fields, the ones I'll be querying are called
'q_high' and 'q_low'.
I also have documents of type 'message' (the child documents) which have
the same q_high and q_low fields
We've modelled it this way as all top level resources can have messages
associated with them.
When we search for resources, we'd also like to search trough all the
messages that are associated with a resource.

Now I want to write a query where:

  • the q_high or q_low field match a string (chicken in the example below)
  • OR the q_high/q_low field match the same string.

When a child document matches, I only need the parent document.

So far, I have the following Bool query:

{
"bool": {
"should": [
{
"multi_match": {
"fields": [
"q_high^2.0",
"q_low^0.75"
],
"query": "chicken"
}
},
{
"has_child": {
"type": "message",
"query": {
"multi_match": {
"fields": [
"q_high^2.0",
"q_low^0.75"
],
"query": "chicken"
}
}
}
}
]
}
}

This works, but the more content I put into the system the lower the score
of child documents get.
When there are only 2 documents in the system (the parent and child) the
child gets a score of about 0.6.
When there are about 660 documents in the system, the score plumets to 0.02

Is there a better way to do queries like this?

Kind regards,

Simon Gaeremynck

--
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.

HI Simon

Why do you care about the absolute score? It's not important. The only
thing that is important is the relative difference between each doc, ie
that more relevant docs appear higher than less relevant.

Note that has_child defaults to not scoring matching children. You have to
explicitly set the score_mode (called score_type in the current
versions of ES, but has been fixed in master to be consistent) to eg `sum``

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

clint

On 18 May 2013 10:39, Simon Gaeremynck gaeremyncks@gmail.com wrote:

Hello,

I'm struggling a bit to write a query that would query fields on a parent
document and the fields on a child document.

first thought, my mapping:
I have documents of type 'resource' (these are the parent docs)
which have a couple of fields, the ones I'll be querying are called
'q_high' and 'q_low'.
I also have documents of type 'message' (the child documents) which have
the same q_high and q_low fields
We've modelled it this way as all top level resources can have messages
associated with them.
When we search for resources, we'd also like to search trough all the
messages that are associated with a resource.

Now I want to write a query where:

  • the q_high or q_low field match a string (chicken in the example below)
  • OR the q_high/q_low field match the same string.

When a child document matches, I only need the parent document.

So far, I have the following Bool query:

{
"bool": {
"should": [
{
"multi_match": {
"fields": [
"q_high^2.0",
"q_low^0.75"
],
"query": "chicken"
}
},
{
"has_child": {
"type": "message",
"query": {
"multi_match": {
"fields": [
"q_high^2.0",
"q_low^0.75"
],
"query": "chicken"
}
}
}
}
]
}
}

This works, but the more content I put into the system the lower the score
of child documents get.
When there are only 2 documents in the system (the parent and child) the
child gets a score of about 0.6.
When there are about 660 documents in the system, the score plumets to 0.02

Is there a better way to do queries like this?

Kind regards,

Simon Gaeremynck

--
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.

--
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.

Hi Clint,

Setting the score_mode fixed it.
In hindsight it's unbelievable that I missed that bit of information in the documentation as it's right there.
Thank you for the patient reply.

Regards,

Simon

On 18 May 2013, at 12:47, Clinton Gormley clint@traveljury.com wrote:

HI Simon

Why do you care about the absolute score? It's not important. The only thing that is important is the relative difference between each doc, ie that more relevant docs appear higher than less relevant.

Note that has_child defaults to not scoring matching children. You have to explicitly set the score_mode (called score_type in the current versions of ES, but has been fixed in master to be consistent) to eg `sum``

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

clint

On 18 May 2013 10:39, Simon Gaeremynck gaeremyncks@gmail.com wrote:
Hello,

I'm struggling a bit to write a query that would query fields on a parent document and the fields on a child document.

first thought, my mapping:
I have documents of type 'resource' (these are the parent docs)
which have a couple of fields, the ones I'll be querying are called 'q_high' and 'q_low'.
I also have documents of type 'message' (the child documents) which have the same q_high and q_low fields
We've modelled it this way as all top level resources can have messages associated with them.
When we search for resources, we'd also like to search trough all the messages that are associated with a resource.

Now I want to write a query where:

  • the q_high or q_low field match a string (chicken in the example below)
  • OR the q_high/q_low field match the same string.

When a child document matches, I only need the parent document.

So far, I have the following Bool query:

{
"bool": {
"should": [
{
"multi_match": {
"fields": [
"q_high^2.0",
"q_low^0.75"
],
"query": "chicken"
}
},
{
"has_child": {
"type": "message",
"query": {
"multi_match": {
"fields": [
"q_high^2.0",
"q_low^0.75"
],
"query": "chicken"
}
}
}
}
]
}
}

This works, but the more content I put into the system the lower the score of child documents get.
When there are only 2 documents in the system (the parent and child) the child gets a score of about 0.6.
When there are about 660 documents in the system, the score plumets to 0.02

Is there a better way to do queries like this?

Kind regards,

Simon Gaeremynck

--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elasticsearch/qhB9PLdON7Q/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.