# Reduce facet/custom\_score cardinality by rounding?

**URL:** <https://discuss.elastic.co/t/reduce-facet-custom-score-cardinality-by-rounding/10252>\
**Category:** Elasticsearch\
**Created:** [January 7, 2013, 4:05pm UTC](https://discuss.elastic.co/t/reduce-facet-custom-score-cardinality-by-rounding/10252 "2013-01-07T16:05:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome\_Gagnon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerome_gagnon/32/2178_2.png) [@Jerome\_Gagnon](https://discuss.elastic.co/u/Jerome_Gagnon)\
**Post date:** [January 7, 2013, 4:05pm UTC](https://discuss.elastic.co/t/reduce-facet-custom-score-cardinality-by-rounding/10252/1 "2013-01-07T16:05:12Z")

</div>

Good Morning People,

I am currently experiencing OOM error, because of facetting and custom  
scoring (doc['field'] access). I'm basically using a long field (timestamp)  
with a custom scoring function to adjust my score by recency. My timestamp  
precision is in milliseconds, but for recency custom scoring, we don't  
really care about this kind of precision. What I thought is, would id  
reduce the RAM usage if I do something like that;

sb.append(String.format(" + %f/(10.0e-9 \* (%d -  
doc['%s'].date.parse('yyyyMMdd')) + 1)",  
(float) set.getValue().getWeight() / 100,  
compareDate, set.getKey()));

Would the cardinality of the field that I'm trying to load be reduced ? Or  
will all the documents fields are still going to be loaded in memory ? That  
would be great if this could work like that, or in other words, would it be  
possible to make it work like that ?

Thanks,

Jerome

--

---

<div class="post-metadata">

**Author:** ![Jerome\_Gagnon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerome_gagnon/32/2178_2.png) [@Jerome\_Gagnon](https://discuss.elastic.co/u/Jerome_Gagnon)\
**Post date:** [January 7, 2013, 6:53pm UTC](https://discuss.elastic.co/t/reduce-facet-custom-score-cardinality-by-rounding/10252/2 "2013-01-07T18:53:16Z")

</div>

This solution is not working (for some reason custom score fail silently  
and returns no results).

But would there be a way to do this ?

On Monday, January 7, 2013 11:05:12 AM UTC-5, Jérôme Gagnon wrote:

> Good Morning People,
> 
> I am currently experiencing OOM error, because of facetting and custom  
> scoring (doc['field'] access). I'm basically using a long field (timestamp)  
> with a custom scoring function to adjust my score by recency. My timestamp  
> precision is in milliseconds, but for recency custom scoring, we don't  
> really care about this kind of precision. What I thought is, would id  
> reduce the RAM usage if I do something like that;
> 
> sb.append(String.format(" + %f/(10.0e-9 \* (%d -  
> doc['%s'].date.parse('yyyyMMdd')) + 1)",  
> (float) set.getValue().getWeight() / 100,  
> compareDate, set.getKey()));
> 
> Would the cardinality of the field that I'm trying to load be reduced ? Or  
> will all the documents fields are still going to be loaded in memory ? That  
> would be great if this could work like that, or in other words, would it be  
> possible to make it work like that ?
> 
> Thanks,
> 
> Jerome

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [January 8, 2013, 7:40pm UTC](https://discuss.elastic.co/t/reduce-facet-custom-score-cardinality-by-rounding/10252/3 "2013-01-08T19:40:26Z")

</div>

One problem with the subtraction is any future date will be negative, so  
will score below all small fractions between 1 and 0.

why not just  
(doc['myDateField']/compareDate)

If the compare date is today or sometime in the future that gives a  
value of 1.0 for doc whose date is the same as right now (or compare  
date), or results in a fraction just below 1.0 as the doc date is older  
and older.  
instead of  
(compareDate - doc['myDateField']... + 1)

I think you might be getting a string as the result of the parse, so it  
doesn't like  
number + string + 1

So I'd try:  
((1.0d \* doc['myDateField'].time())/compareDate)

Maybe would be:  
sb.append(String.format(" + %f/(10.0e-9 \* (_% **f** D **/ (1.0D**_  
doc['%s'].**time()**)\* + 1)",  
(float) set.getValue().getWeight() / 100, compareDate \* 1.0f,  
set.getKey()));  
I'm not sure what the rest of your script looks like, so not sure how  
the fixed weight factor of 1x10^-9 and the +1 enter in.

I was doing something similar and check the round of a float. It is in  
the range of "milliseconds per decade".

-Paul

On 1/7/2013 10:53 AM, Jérôme Gagnon wrote:

> This solution is not working (for some reason custom score fail  
> silently and returns no results).  
> But would there be a way to do this ?
> 
> On Monday, January 7, 2013 11:05:12 AM UTC-5, Jérôme Gagnon wrote:
> 
> ```
> Good Morning People,
> 
> I am currently experiencing OOM error, because of facetting and
> custom scoring (doc['field'] access). I'm basically using a long
> field (timestamp) with a custom scoring function to adjust my
> score by recency. My timestamp precision is in milliseconds, but
> for recency custom scoring, we don't really care about this kind
> of precision. What I thought is, would id reduce the RAM usage if
> I do something like that;
> 
> sb.append(String.format(" + %f/(10.0e-9 * (%d -
> doc['%s'].date.parse('yyyyMMdd')) + 1)",
> (float) set.getValue().getWeight() / 100, compareDate,
> set.getKey()));
> 
> Would the cardinality of the field that I'm trying to load be
> reduced ? Or will all the documents fields are still going to be
> loaded in memory ? That would be great if this could work like
> that, or in other words, would it be possible to make it work like
> that ?
> 
> Thanks,
> 
> Jerome
> 
> ```
> 
> --

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:57am UTC](https://discuss.elastic.co/t/reduce-facet-custom-score-cardinality-by-rounding/10252/4 "2017-07-06T02:57:20Z")

</div>

Closed on July 6, 2017, 2:57am UTC


