# How to combine function\_score with filters without a query?

**URL:** https://discuss.elastic.co/t/how-to-combine-function-score-with-filters-without-a-query/75883
**Category:** Elasticsearch
**Created:** [February 21, 2017, 1:20pm UTC](https://discuss.elastic.co/t/how-to-combine-function-score-with-filters-without-a-query/75883 "2017-02-21T13:20:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![diegoholiveira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diegoholiveira/32/13475_2.png) [@diegoholiveira](https://discuss.elastic.co/u/diegoholiveira)
#### Post date: [February 21, 2017, 1:20pm UTC](https://discuss.elastic.co/t/how-to-combine-function-score-with-filters-without-a-query/75883/1 "2017-02-21T13:20:15Z")

</div>

I'm trying to use decay functions (score\_functions) with filters. This is my query when the user puts with a query (and it's works perfectly to me):

```
{
  "query":{
    "function_score":{
      "query":{
        "bool":{
          "filter":[
            {
              "range":{"end_date":{"gt":"2017-02-21T10:12:51-03:00"}}
            },
            {
              "term":{"is_published":true}
            },
            {
              "term":{"is_private":false}
            },
            {
              "term":{"is_cancelled":false}
            },
            {
              "term":{"is_closed":false}
            },
            {
              "exists":{"field":"coordinates"}
            }
          ],
          "must":[
            {
              "multi_match":{
                "cutoff_frequency":0.001,
                "query":"carnaval",
                "boost":10,
                "fields":["title","title.folded"]
              }
            },
            {
              "multi_match":{
                "query":"carnaval",
                "boost":3,
                "type":"phrase",
                "fields":["description","description.folded"]
              }
            }
          ]
        }
      },
      "functions":[
        {
          "gauss":{
            "start_date":{
              "origin":"2017-02-21T10:12:51-03:00",
              "scale":"2d"
            }
          }
        },
        {
          "gauss":{
            "coordinates":{
              "origin":{
                "lat":-19.9393853,
                "lon":-43.9384061
              },
              "scale":"10km"
            }
          }
        }
      ]
    }
  }
}

```

My problem is, I allow the user to search without a query, and I must keep the filters. I try to do this without success:

```
{
  "query":{
    "function_score":{
      "query":{
        "bool":{
          "filter":[
            {
              "range":{"end_date":{"gt":"2017-02-21T10:12:51-03:00"}}
            },
            {
              "term":{"is_published":true}
            },
            {
              "term":{"is_private":false}
            },
            {
              "term":{"is_cancelled":false}
            },
            {
              "term":{"is_closed":false}
            },
            {
              "exists":{"field":"coordinates"}
            }
          ]
        }
      },
      "functions":[
        {
          "gauss":{
            "start_date":{
              "origin":"2017-02-21T10:12:51-03:00",
              "scale":"2d"
            }
          }
        },
        {
          "gauss":{
            "coordinates":{
              "origin":{
                "lat":-19.9393853,
                "lon":-43.9384061
              },
              "scale":"10km"
            }
          }
        }
      ]
    }
  }
}

```

I also try other variations without success. So, my question is: how can I combine successfully score\_functions and filters?

Thanks 🙂

---

<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: [March 21, 2017, 1:21pm UTC](https://discuss.elastic.co/t/how-to-combine-function-score-with-filters-without-a-query/75883/2 "2017-03-21T13:21:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
