# Combining Function Score query and filtering

**URL:** https://discuss.elastic.co/t/combining-function-score-query-and-filtering/234802
**Category:** Elasticsearch
**Created:** [May 28, 2020, 6:57pm UTC](https://discuss.elastic.co/t/combining-function-score-query-and-filtering/234802 "2020-05-28T18:57:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![chrisbag](https://avatars.discourse-cdn.com/v4/letter/c/5f8ce5/32.png) [@chrisbag](https://discuss.elastic.co/u/chrisbag)
#### Post date: [May 28, 2020, 6:57pm UTC](https://discuss.elastic.co/t/combining-function-score-query-and-filtering/234802/1 "2020-05-28T18:57:24Z")

</div>

Hello everybody,  
I have been struggling all afternoon trying to combine a filter with my score function and script. I have been struggling just to implement a simple filter (I do not wish to impact the scoring function, just score the "Appartments").  
I would love some outside help 🙂  
Thanks a lot

Here is the filter I am trying to combine

```auto
"query": { 
    "bool": { 
      "filter": [ 
        { "term": { "bien_type": "Appartment" }},
      ]
    }
  }

```

with this functional score functional and script field

```auto
      query: {
        function_score: {
          functions: [
            {
              gauss: {
                date_mutation: {
                  origin: "2019-12-31",
                  offset: "360d",
                  scale: "1800d",
                  decay: 0.1,
                },
              },
            },
            {
              gauss: {
                location: {
                  origin: { lat: latitude, lon: longitude },
                  offset: "0.1km",
                  scale: "0.9km",
                  decay: 0.1,
                },
              },
            },
          ],
          score_mode: "multiply",
        },
      },
      _source: true,
      script_fields: {
        distance: {
          script: {
            inline: "doc['location'].arcDistance(params.lat,params.lon)",
            lang: "painless",
            params: {
              lat: parseFloat(latitude),
              lon: parseFloat(longitude),
            },
          },
        },
      },

```

---

<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: [June 25, 2020, 6:57pm UTC](https://discuss.elastic.co/t/combining-function-score-query-and-filtering/234802/2 "2020-06-25T18:57:26Z")

</div>

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