# Filtering on a Function Score Element (Not filtering as expected)

**URL:** <https://discuss.elastic.co/t/filtering-on-a-function-score-element-not-filtering-as-expected/20586>\
**Category:** Elasticsearch\
**Created:** [November 5, 2014, 6:58pm UTC](https://discuss.elastic.co/t/filtering-on-a-function-score-element-not-filtering-as-expected/20586 "2014-11-05T18:58:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren\_McDaniel](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@Darren\_McDaniel](https://discuss.elastic.co/u/Darren_McDaniel)\
**Post date:** [November 5, 2014, 6:58pm UTC](https://discuss.elastic.co/t/filtering-on-a-function-score-element-not-filtering-as-expected/20586/1 "2014-11-05T18:58:51Z")

</div>

Hey Guys,

I have a question to put on you guys again.. 🙂

in the query below I have a nested query element with a function score...  
BUT... it doesnt appear to be filtering based on that function like I had  
hoped....

any thoughts?

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"and": [  
{  
"terms": {  
"owk": [  
23621  
]  
}  
},  
{  
"terms": {  
"oowk": [  
23621  
]  
}  
},  
{  
"term": {  
"ismd": true  
}  
},  
{  
"and": [  
{  
"and": [

```
                       {
                          "term": {
                             "ipl": false
                          }
                       },
                       {
                          "terms": {
                             "pwk": [
                                21754
                             ]
                          }
                       },
                       {
                          "range": {
                             "lsdt": {
                                "gte": "2014-09-20",
                                "lte": "2014-09-30"
                             }
                          }
                       },
                       {
                          "term": {
                             "isb": false
                          }
                       }
                    ]
                 },
                 {
                    "query": {
                        
                       "function_score": {
                          "boost_mode": "multiply",
                          "functions": [
                             {
                                "script_score": {
                                   "params": {
                                      "min_value": 2,
                                      "max_value": 2
                                   },
                                   "script": "(max_value == null || 

```

\_score \<= max\_value) && (min\_value == null || \_score \>= min\_value)?1:-1"  
}  
}  
],  
"query": {  
"filtered": {  
"query": {  
"has\_child": {  
"type": "service",  
"score\_type": "total",  
"query": {  
"filtered": {  
"filter": {  
"and": [  
{  
"terms": {  
"owk": [  
23621  
]  
}  
},  
{  
"range": {  
"dt": {  
"gte":  
"2014-09-20",  
"lte":  
"2014-09-30"  
}  
}  
}  
]  
}  
}  
}  
}  
},  
"filter": {  
"terms": {  
"owk": [  
23621  
]  
}  
}  
}  
}  
}  
}  
}  
]  
}  
]  
}  
}  
},  
"from": 0,  
"size": 0,  
"aggs": {  
"unique": {  
"cardinality": {  
"field": "hhk",  
"precision\_threshold": 40000  
}  
}  
}  
}

--  
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/67a55e78-15ff-4616-a637-e565de30cb9e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/67a55e78-15ff-4616-a637-e565de30cb9e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Darren\_McDaniel](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@Darren\_McDaniel](https://discuss.elastic.co/u/Darren_McDaniel)\
**Post date:** [November 6, 2014, 3:01pm UTC](https://discuss.elastic.co/t/filtering-on-a-function-score-element-not-filtering-as-expected/20586/2 "2014-11-06T15:01:41Z")

</div>

So my expected results would for the results that the results from the  
function\_score filter would filter out results where the parent had n  
number of children... but instead, I'm getting all the results instead of a  
filtered set....

I could really use some advice here... Or let me know what more I can  
provide that would get results?

--  
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/72caea25-560e-4e33-b229-93d6e1aea7a5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/72caea25-560e-4e33-b229-93d6e1aea7a5%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:51am UTC](https://discuss.elastic.co/t/filtering-on-a-function-score-element-not-filtering-as-expected/20586/3 "2017-07-06T00:51:48Z")

</div>


