Best option for scoring documents based on custom relevancy score

Hi all,

I have a set of extracted terms, with associated relevancy scores and other
metadata, from each document. I'd like to scale _score by the relevancy of
the matched terms. It seems to me there are at least two approaches for
solving this problem:

  1. Nested Document:

In this case, my mapping would look like:

{
"contentDocument": {
"properties": {
"content": {
"type": "string"
},
"terms": {
"type": "nested",
"fields": {
"text": {
"type": "string",
},
"relevance": {
"type": "float"
}
}
}
}
}
}

Then I could query using:

{
"query": {
"nested": {
"score_mode": "max",
"path": "terms",
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "multiply",
"query": {
"match": {
"terms.text": ""
}
},
"functions": [
{
"field_value_factor": {
"field": "terms.relevance"
}
}
]
}
}
}
}
}

This seems to work as expected on the small prototype I've built.

  1. Parent/Child Documents:

In this case, my mapping would look like:

{
"contentDocument": {
"properties": {
"content": {
"type": "string"
}
}
}
}
{
"termDocument": {
"_parent": {
"type": "contentDocument"
},
"properties": {
"text": {
"type": "string"
},
"relevance": {
"type": "float"
}
}
}
}

Then I could query using:

{
"query": {
"has_child": {
"type": "termDocument",
"score_mode": "max",
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "multiply",
"query": {
"match": {
"text": ""
}
},
"functions": [
{
"field_value_factor": {
"field": "termDocument.relevance"
}
}
]
}
}
}
}
}

This also seems to work in the prototype.

So, both options seem to work, which is great! However, I'm not sure if
there are any performance (or other) concerns with approaches? We will have
millions of documents (and associated terms), so we need our solution to
scale well. It seems to me that the nested approach is conceptually more
straightforward, so I'm leaning in that directly, but wanted to get input
for larger ES community.

Please let me know if there is any other options that might work better!
I've also considered using payloads:

https://groups.google.com/forum/#!searchin/elasticsearch/Scott$20Decker|sort:date/elasticsearch/gEcBVhSynnY/4N1XD5NyseMJ

However, I'm not sure that will work for us as there is metadata, other
than relevancy, I'd like to store about each term.

Thank you!

--
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/92296554-97e0-4755-a648-72224c58fea4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

1 Like

Payloads work better when you need to increase the relevancy at the term
level. Using a field that contains the relevancy boost is applied at the
document level, so it depends on how specific you need your boosting to be.
Boosting at the document level will be more efficient since you are looking
up only one value.

Scoring with a function_score will always have some impact, but it should
be relatively minor when using field_value_factor, which is probably the
best document level boosting mechanism you could use.

Cheers,

Ivan

On Wed, Aug 27, 2014 at 5:52 AM, hespoddi chris@publishthis.com wrote:

Hi all,

I have a set of extracted terms, with associated relevancy scores and
other metadata, from each document. I'd like to scale _score by the
relevancy of the matched terms. It seems to me there are at least two
approaches for solving this problem:

  1. Nested Document:

In this case, my mapping would look like:

{
"contentDocument": {
"properties": {
"content": {
"type": "string"
},
"terms": {
"type": "nested",
"fields": {
"text": {
"type": "string",
},
"relevance": {
"type": "float"
}
}
}
}
}
}

Then I could query using:

{
"query": {
"nested": {
"score_mode": "max",
"path": "terms",
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "multiply",
"query": {
"match": {
"terms.text": ""
}
},
"functions": [
{
"field_value_factor": {
"field": "terms.relevance"
}
}
]
}
}
}
}
}

This seems to work as expected on the small prototype I've built.

  1. Parent/Child Documents:

In this case, my mapping would look like:

{
"contentDocument": {
"properties": {
"content": {
"type": "string"
}
}
}
}
{
"termDocument": {
"_parent": {
"type": "contentDocument"
},
"properties": {
"text": {
"type": "string"
},
"relevance": {
"type": "float"
}
}
}
}

Then I could query using:

{
"query": {
"has_child": {
"type": "termDocument",
"score_mode": "max",
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "multiply",
"query": {
"match": {
"text": ""
}
},
"functions": [
{
"field_value_factor": {
"field": "termDocument.relevance"
}
}
]
}
}
}
}
}

This also seems to work in the prototype.

So, both options seem to work, which is great! However, I'm not sure if
there are any performance (or other) concerns with approaches? We will have
millions of documents (and associated terms), so we need our solution to
scale well. It seems to me that the nested approach is conceptually more
straightforward, so I'm leaning in that directly, but wanted to get input
for larger ES community.

Please let me know if there is any other options that might work better!
I've also considered using payloads:

Redirecting to Google Groups

However, I'm not sure that will work for us as there is metadata, other
than relevancy, I'd like to store about each term.

Thank you!

--
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/92296554-97e0-4755-a648-72224c58fea4%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/92296554-97e0-4755-a648-72224c58fea4%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/CALY%3DcQAouQK1FNny57LJ5uzLnVbwQ2PtmkeNhOp_g65xgxFpYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Okay... Thanks! I think we're going to go with the nested approach then.

On Wednesday, August 27, 2014 10:24:16 AM UTC-4, Ivan Brusic wrote:

Payloads work better when you need to increase the relevancy at the term
level. Using a field that contains the relevancy boost is applied at the
document level, so it depends on how specific you need your boosting to be.
Boosting at the document level will be more efficient since you are looking
up only one value.

Scoring with a function_score will always have some impact, but it should
be relatively minor when using field_value_factor, which is probably the
best document level boosting mechanism you could use.

Cheers,

Ivan

On Wed, Aug 27, 2014 at 5:52 AM, hespoddi <ch...@publishthis.com
<javascript:>> wrote:

Hi all,

I have a set of extracted terms, with associated relevancy scores and
other metadata, from each document. I'd like to scale _score by the
relevancy of the matched terms. It seems to me there are at least two
approaches for solving this problem:

  1. Nested Document:

In this case, my mapping would look like:

{
"contentDocument": {
"properties": {
"content": {
"type": "string"
},
"terms": {
"type": "nested",
"fields": {
"text": {
"type": "string",
},
"relevance": {
"type": "float"
}
}
}
}
}
}

Then I could query using:

{
"query": {
"nested": {
"score_mode": "max",
"path": "terms",
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "multiply",
"query": {
"match": {
"terms.text": ""
}
},
"functions": [
{
"field_value_factor": {
"field": "terms.relevance"
}
}
]
}
}
}
}
}

This seems to work as expected on the small prototype I've built.

  1. Parent/Child Documents:

In this case, my mapping would look like:

{
"contentDocument": {
"properties": {
"content": {
"type": "string"
}
}
}
}
{
"termDocument": {
"_parent": {
"type": "contentDocument"
},
"properties": {
"text": {
"type": "string"
},
"relevance": {
"type": "float"
}
}
}
}

Then I could query using:

{
"query": {
"has_child": {
"type": "termDocument",
"score_mode": "max",
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "multiply",
"query": {
"match": {
"text": ""
}
},
"functions": [
{
"field_value_factor": {
"field": "termDocument.relevance"
}
}
]
}
}
}
}
}

This also seems to work in the prototype.

So, both options seem to work, which is great! However, I'm not sure if
there are any performance (or other) concerns with approaches? We will have
millions of documents (and associated terms), so we need our solution to
scale well. It seems to me that the nested approach is conceptually more
straightforward, so I'm leaning in that directly, but wanted to get input
for larger ES community.

Please let me know if there is any other options that might work better!
I've also considered using payloads:

Redirecting to Google Groups

However, I'm not sure that will work for us as there is metadata, other
than relevancy, I'd like to store about each term.

Thank you!

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/92296554-97e0-4755-a648-72224c58fea4%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/92296554-97e0-4755-a648-72224c58fea4%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/62b4a2c9-518a-4815-81d7-1b60036b48a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.