# Function score filter function doesn't seem to be cached

**URL:** <https://discuss.elastic.co/t/function-score-filter-function-doesnt-seem-to-be-cached/22141>\
**Category:** Elasticsearch\
**Created:** [February 12, 2015, 7:47pm UTC](https://discuss.elastic.co/t/function-score-filter-function-doesnt-seem-to-be-cached/22141 "2015-02-12T19:47:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fforster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fforster/32/904_2.png) [@fforster](https://discuss.elastic.co/u/fforster)\
**Post date:** [February 12, 2015, 7:47pm UTC](https://discuss.elastic.co/t/function-score-filter-function-doesnt-seem-to-be-cached/22141/1 "2015-02-12T19:47:37Z")

</div>

I am using a function score with a function filter to score a subset of  
results higher. I specify to cache the function filter, but its performance  
is slower and slower the more clauses I add to the filter.

A query with 2 geo\_polygons clauses returns relatively fast (30ms), but the  
more polygons clauses I add the slower it gets. With 50 polygons the call  
slows to 1s. Does elasticsearch actually cache the filter?

Example query with 2 geo\_polygons clauses:  
{  
"query": {  
"function\_score": {  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"city": "LA"  
}  
}  
]  
}  
},  
"functions": [  
{  
"filter": {  
"bool": {  
"should": [  
{  
"geo\_polygon": {  
"location": {  
"points": [  
[  
-118.3971081,  
34.081519  
],  
[  
-118.3440351,  
34.081519  
],  
[  
-118.3440351,  
34.131086  
],  
[  
-118.3971081,  
34.131086  
]  
]  
}  
}  
},  
{  
"geo\_polygon": {  
"location": {  
"points": [  
[  
-118.3907139,  
34.05576  
],  
[  
-118.361375,  
34.05576  
],  
[  
-118.361375,  
34.083811  
],  
[  
-118.3907139,  
34.083811  
]  
]  
}  
}  
}  
],  
"\_cache": true  
}  
},  
"boost\_factor": 2  
}  
],  
"score\_mode": "sum"  
}  
}  
}

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c990d908-2b15-4797-9300-22a71aeb4972%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c990d908-2b15-4797-9300-22a71aeb4972%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jason\_Wee](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jason\_Wee](https://discuss.elastic.co/u/Jason_Wee)\
**Post date:** [February 13, 2015, 12:54am UTC](https://discuss.elastic.co/t/function-score-filter-function-doesnt-seem-to-be-cached/22141/2 "2015-02-13T00:54:27Z")

</div>

set explain to true and read the explain output if cache is use?

Jason

On Fri, Feb 13, 2015 at 3:47 AM, [fforster@homeaway.com](mailto:fforster@homeaway.com) wrote:

> I am using a function score with a function filter to score a subset of  
> results higher. I specify to cache the function filter, but its performance  
> is slower and slower the more clauses I add to the filter.
> 
> A query with 2 geo\_polygons clauses returns relatively fast (30ms), but  
> the more polygons clauses I add the slower it gets. With 50 polygons the  
> call slows to 1s. Does elasticsearch actually cache the filter?
> 
> Example query with 2 geo\_polygons clauses:  
> {  
> "query": {  
> "function\_score": {  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "city": "LA"  
> }  
> }  
> ]  
> }  
> },  
> "functions": [  
> {  
> "filter": {  
> "bool": {  
> "should": [  
> {  
> "geo\_polygon": {  
> "location": {  
> "points": [  
> [  
> -118.3971081,  
> 34.081519  
> ],  
> [  
> -118.3440351,  
> 34.081519  
> ],  
> [  
> -118.3440351,  
> 34.131086  
> ],  
> [  
> -118.3971081,  
> 34.131086  
> ]  
> ]  
> }  
> }  
> },  
> {  
> "geo\_polygon": {  
> "location": {  
> "points": [  
> [  
> -118.3907139,  
> 34.05576  
> ],  
> [  
> -118.361375,  
> 34.05576  
> ],  
> [  
> -118.361375,  
> 34.083811  
> ],  
> [  
> -118.3907139,  
> 34.083811  
> ]  
> ]  
> }  
> }  
> }  
> ],  
> "\_cache": true  
> }  
> },  
> "boost\_factor": 2  
> }  
> ],  
> "score\_mode": "sum"  
> }  
> }  
> }
> 
> --  
> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c990d908-2b15-4797-9300-22a71aeb4972%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c990d908-2b15-4797-9300-22a71aeb4972%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c990d908-2b15-4797-9300-22a71aeb4972%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c990d908-2b15-4797-9300-22a71aeb4972%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHO4itze5wyDX%2Bp3OC%2BPpN%3Db1XHLQQvKb68ZEeOnAA9tEAwiBw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHO4itze5wyDX%2Bp3OC%2BPpN%3Db1XHLQQvKb68ZEeOnAA9tEAwiBw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![fforster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fforster/32/904_2.png) [@fforster](https://discuss.elastic.co/u/fforster)\
**Post date:** [February 13, 2015, 3:18pm UTC](https://discuss.elastic.co/t/function-score-filter-function-doesnt-seem-to-be-cached/22141/3 "2015-02-13T15:18:32Z")

</div>

Explain shows the cached filter, but based on the time it takes (took: 528)  
I doubt it's used efficiently

{  
value: 2  
description: Math.min of  
details: [  
{  
value: 2  
description: function score, score mode [sum]  
details: [  
{  
value: 2  
description: function score, product of:  
details: [  
{  
value: 1  
description: match filter: cache(BooleanFilter(+cache(olbValid:T)  
+BooleanFilter(GeoPolygonFilter(location, [[34.081519, -118.3971081],  
[34.081519, -118.3440351], [34.131086, -118.3440351], [34.131086,  
-118.3971081], [34.081519, -118.3971081]]) GeoPolygonFilter(location,  
[[34.05576, -118.3907139], [34.05576, -118.361375], [34.083811,  
-118.361375], [34.083811, -118.3907139], [34.05576, -118.3907139]])  
GeoPolygonFilter(location, [[34.0412758, -118.528682], [34.0412758,  
-118.453384], [34.1324337, -118.453384], [34.1324337, -118.528682],  
[34.0412758, -118.528682]]) GeoPolygonFilter(location, [[34.0518801,  
-118.28436], [34.0518801, -118.2665471], [34.072782, -118.2665471],  
[34.072782, -118.28436], [34.0518801, -118.28436]])  
GeoPolygonFilter(location, [[34.017233, -118.46146], [34.017233,  
-118.39865], [34.0532549, -118.39865], [34.0532549, -118.46146],  
[34.017233, -118.46146]]) GeoPolygonFilter(location, [[33.973535,  
-118.455804], [33.973535, -118.407918], [34.0268609, -118.407918],  
[34.0268609, -118.455804], [33.973535, -118.455804]])  
GeoPolygonFilter(location, [[34.0491411, -118.4215721], [34.0491411,  
-118.406023], [34.0639819, -118.406023], [34.0639819, -118.4215721],  
[34.0491411, -118.4215721]]) GeoPolygonFilter(location, [[34.1036901,  
-118.3678789], [34.1036901, -118.3010089], [34.152483, -118.3010089],  
[34.152483, -118.3678789], [34.1036901, -118.3678789]])  
GeoPolygonFilter(location, [[34.0790469, -118.396506], [34.0790469,  
-118.3669411], [34.1075319, -118.3669411], [34.1075319, -118.396506],  
[34.0790469, -118.396506]]) GeoPolygonFilter(location, [[34.048743,  
-118.259363], [34.048743, -118.250157], [34.056087, -118.250157],  
[34.056087, -118.259363], [34.048743, -118.259363]])  
GeoPolygonFilter(location, [[34.0734518, -118.4822519], [34.0734518,  
-118.422647], [34.132908, -118.422647], [34.132908, -118.4822519],  
[34.0734518, -118.4822519]]) GeoPolygonFilter(location, [[33.9658801,  
-118.4404339], [33.9658801, -118.397569], [33.9839929, -118.397569],  
[33.9839929, -118.4404339], [33.9658801, -118.4404339]])  
GeoPolygonFilter(location, [[34.065094, -118.4423781], [34.065094,  
-118.3867129], [34.1354771, -118.3867129], [34.1354771, -118.4423781],  
[34.065094, -118.4423781]]) GeoPolygonFilter(location, [[34.057085,  
-118.390748], [34.057085, -118.3720269], [34.072342, -118.3720269],  
[34.072342, -118.390748], [34.057085, -118.390748]])  
GeoPolygonFilter(location, [[34.0541081, -118.4163189], [34.0541081,  
-118.389668], [34.069207, -118.389668], [34.069207, -118.4163189],  
[34.0541081, -118.4163189]]) GeoPolygonFilter(location, [[33.9755489,  
-118.419822], [33.9755489, -118.37006], [34.0173769, -118.37006],  
[34.0173769, -118.419822], [33.9755489, -118.419822]])  
GeoPolygonFilter(location, [[33.9016261, -118.4371209], [33.9016261,  
-118.3735181], [33.931641, -118.3735181], [33.931641, -118.4371209],  
[33.9016261, -118.4371209]]) GeoPolygonFilter(location, [[33.8504661,  
-118.414124], [33.8504661, -118.384853], [33.878445, -118.384853],  
[33.878445, -118.414124], [33.8504661, -118.414124]])  
GeoPolygonFilter(location, [[33.9955069, -119.0699391], [33.9955069,  
-118.557949], [34.1443899, -118.557949], [34.1443899, -119.0699391],  
[33.9955069, -119.0699391]]) GeoPolygonFilter(location, [[33.8728038,  
-118.430009], [33.8728038, -118.3785991], [33.9061261, -118.3785991],  
[33.9061261, -118.430009], [33.8728038, -118.430009]])  
GeoPolygonFilter(location, [[34.024999, -118.5875051], [34.024999,  
-118.495177], [34.13165, -118.495177], [34.13165, -118.5875051],  
[34.024999, -118.5875051]]) GeoPolygonFilter(location, [[33.8041178,  
-118.405002], [33.8041178, -118.3703771], [33.8580759, -118.3703771],  
[33.8580759, -118.405002], [33.8041178, -118.405002]])  
GeoPolygonFilter(location, [[34.041016, -118.651771], [34.041016,  
-118.5512071], [34.145413, -118.5512071], [34.145413, -118.651771],  
[34.041016, -118.651771]]) GeoPolygonFilter(location, [[33.9765188,  
-118.4904589], [33.9765188, -118.4443409], [34.0147499, -118.4443409],  
[34.0147499, -118.4904589], [33.9765188, -118.4904589]])  
GeoPolygonFilter(location, [[33.95876, -118.471863], [33.95876,  
-118.4241309], [33.994206, -118.4241309], [33.994206, -118.471863],  
[33.95876, -118.471863]]) GeoPolygonFilter(location, [[33.9163209,  
-118.4640851], [33.9163209, -118.41719], [33.974274, -118.41719],  
[33.974274, -118.4640851], [33.9163209, -118.4640851]])  
GeoPolygonFilter(location, [[33.993572, -118.508206], [33.993572,  
-118.483473], [34.0256331, -118.483473], [34.0256331, -118.508206],  
[33.993572, -118.508206]]) GeoPolygonFilter(location, [[34.018217,  
-118.521865], [34.018217, -118.4837659], [34.05056, -118.4837659],  
[34.05056, -118.521865], [34.018217, -118.521865]])  
GeoPolygonFilter(location, [[34.0130348, -118.51226], [34.0130348,  
-118.470385], [34.046699, -118.470385], [34.046699, -118.51226],  
[34.0130348, -118.51226]]) GeoPolygonFilter(location, [[34.012045,  
-118.490271], [34.012045, -118.4528569], [34.0409041, -118.4528569],  
[34.0409041, -118.490271], [34.012045, -118.490271]])  
GeoPolygonFilter(location, [[33.9954159, -118.4917131], [33.9954159,  
-118.4435171], [34.0278161, -118.4435171], [34.0278161, -118.4917131],  
[33.9954159, -118.4917131]]) GeoPolygonFilter(location, [[34.119054,  
-118.4225019], [34.119054, -118.35193], [34.157517, -118.35193],  
[34.157517, -118.4225019], [34.119054, -118.4225019]])  
GeoPolygonFilter(location, [[34.063724, -118.4504281], [34.063724,  
-118.437812], [34.076625, -118.437812], [34.076625, -118.4504281],  
[34.063724, -118.4504281]]))))  
}  
{  
value: 2  
description: static boost factor  
details: [  
{  
value: 2  
description: boostFactor  
}  
]  
}  
]  
}  
]  
}

On Thursday, February 12, 2015 at 1:47:37 PM UTC-6, [ffor...@homeaway.com](mailto:ffor...@homeaway.com)  
wrote:

> I am using a function score with a function filter to score a subset of  
> results higher. I specify to cache the function filter, but its performance  
> is slower and slower the more clauses I add to the filter.
> 
> A query with 2 geo\_polygons clauses returns relatively fast (30ms), but  
> the more polygons clauses I add the slower it gets. With 50 polygons the  
> call slows to 1s. Does elasticsearch actually cache the filter?
> 
> Example query with 2 geo\_polygons clauses:  
> {  
> "query": {  
> "function\_score": {  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "city": "LA"  
> }  
> }  
> ]  
> }  
> },  
> "functions": [  
> {  
> "filter": {  
> "bool": {  
> "should": [  
> {  
> "geo\_polygon": {  
> "location": {  
> "points": [  
> [  
> -118.3971081,  
> 34.081519  
> ],  
> [  
> -118.3440351,  
> 34.081519  
> ],  
> [  
> -118.3440351,  
> 34.131086  
> ],  
> [  
> -118.3971081,  
> 34.131086  
> ]  
> ]  
> }  
> }  
> },  
> {  
> "geo\_polygon": {  
> "location": {  
> "points": [  
> [  
> -118.3907139,  
> 34.05576  
> ],  
> [  
> -118.361375,  
> 34.05576  
> ],  
> [  
> -118.361375,  
> 34.083811  
> ],  
> [  
> -118.3907139,  
> 34.083811  
> ]  
> ]  
> }  
> }  
> }  
> ],  
> "\_cache": true  
> }  
> },  
> "boost\_factor": 2  
> }  
> ],  
> "score\_mode": "sum"  
> }  
> }  
> }

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/93cf1724-5871-4c45-a121-da049dfa184d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/93cf1724-5871-4c45-a121-da049dfa184d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:32am UTC](https://discuss.elastic.co/t/function-score-filter-function-doesnt-seem-to-be-cached/22141/4 "2017-07-06T00:32:56Z")

</div>


