How to combine function_score with filters without a query?

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 :slight_smile:

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