# FunctionScoreQueryBuilder should support filter mode

**URL:** <https://discuss.elastic.co/t/functionscorequerybuilder-should-support-filter-mode/45651>\
**Category:** Elasticsearch\
**Created:** [March 29, 2016, 6:42am UTC](https://discuss.elastic.co/t/functionscorequerybuilder-should-support-filter-mode/45651 "2016-03-29T06:42:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadeInChina](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@MadeInChina](https://discuss.elastic.co/u/MadeInChina)\
**Post date:** [March 29, 2016, 6:42am UTC](https://discuss.elastic.co/t/functionscorequerybuilder-should-support-filter-mode/45651/1 "2016-03-29T06:42:37Z")

</div>

Hi all, i just found a interesting issue.

[enter link description here](https://github.com/elastic/elasticsearch/issues/17374)

i'm doing the elastic optimization stuffs  
When run below code, average tooks 200~300 milliseconds

```
    {
      "from" : 0,
      "size" : 10,
      "query":
    {
      "function_score" : {
          "query" : {
                "bool" : {
                  "must" : [ {
                    "range" : {
                      "timestamp" : {
                        "from" : "1457403235000",
                        "to" : "1458008035000",
                        "include_lower" : true,
                        "include_upper" : true
                      }
                    }
                  }, {
                    "term" : {
                      "type" : "image"
                    }
                  }, {
                    "geo_bbox" : {
                      "geo" : {
                        "top_left" : [-110.80651, 43.44131],
                        "bottom_right" : [-110.804, 43.4403]
                      },
                    "type": "indexed"
                    }
                  } ]
                }
              },
          "functions" : [ {
            "script_score" : {
              "script" : {
                "file" : "hot_score",
                "params" : {
                  "nowTime" : "1458008709945",
                  "gravity" : "2.0"
                }
              }
            }
          } ]
        }
      }     
    }

```

BUT ONCE change query to filter after function\_score,it's only tooks 37~38 milliseconds

```
    {
      "from" : 0,
      "size" : 10,
      "query":
    {
      "function_score" : {
          "filter" : {
                "bool" : {
                  "must" : [ {
                    "range" : {
                      "timestamp" : {
                        "from" : "1457403235000",
                        "to" : "1458008035000",
                        "include_lower" : true,
                        "include_upper" : true
                      }
                    }
                  }, {
                    "term" : {
                      "type" : "image"
                    }
                  }, {
                    "geo_bbox" : {
                      "geo" : {
                        "top_left" : [-110.80651, 43.44131],
                        "bottom_right" : [-110.804, 43.4403]
                      },
                    "type": "indexed"
                    }
                  } ]
                }
              },
          "functions" : [ {
            "script_score" : {
              "script" : {
                "file" : "hot_score",
                "params" : {
                  "nowTime" : "1458008709945",
                  "gravity" : "2.0"
                }
              }
            }
          } ]
        }
      }     
    }

```

So i think the filter is better than query.

---

<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 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/functionscorequerybuilder-should-support-filter-mode/45651/2 "2017-07-05T23:00:20Z")

</div>


