# Function\_score multi field filters together

**URL:** <https://discuss.elastic.co/t/function-score-multi-field-filters-together/228250>\
**Category:** Elasticsearch\
**Created:** [April 16, 2020, 5:52am UTC](https://discuss.elastic.co/t/function-score-multi-field-filters-together/228250 "2020-04-16T05:52:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahdi\_Bahari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahdi_bahari/32/66409_2.png) [@Mahdi\_Bahari](https://discuss.elastic.co/u/Mahdi_Bahari)\
**Post date:** [April 16, 2020, 5:52am UTC](https://discuss.elastic.co/t/function-score-multi-field-filters-together/228250/1 "2020-04-16T05:52:33Z")

</div>

this is sample collection that's I want to sort result per custom score in elastic search in so try to read documents so founded function score do it for me  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)

[![enter image description here](https://i.stack.imgur.com/Jt5pM.png)](https://i.stack.imgur.com/Jt5pM.png)  
I have got searching like below and It works properly.  
this code sort list Based on Score

```auto
{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
          { "match_all": { }}
          ],
          "must_not": [],
          "should": []
        }
      },
      "boost": "5",
      "functions": [
        {
          "filter":{
            "term": {
                "soldier": "0"
              }
          }, "weight": 4
        },
           {
          "filter":{
            "term": {
                "married": "0"
              }
          }, "weight": 3
        }
    
      ],
      "score_mode": "sum"
    }
  }
}

```

But I want filter soldier and married altogether and have one weight for both of them.  
such as below but It works wrong and does't sort return data Base on score  
Do you have any idea ?what is it solution for logical and between filter and set one weight for them?

thank you please help me

```auto
   {
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
          { "match_all": { }}
          ],
          "must_not": [],
          "should": []
        }
      },
      "boost": "5",
      "functions": [
        {
          "filter": [
            {
              "term": {
                "soldier": "0"
              }
            },
            {
              "term": {
                "married": "1"
              }
            }
          ],
          "weight": 4
        }
      ],
      "score_mode": "sum"
    }
  }
}

```

---

<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:** [May 14, 2020, 5:52am UTC](https://discuss.elastic.co/t/function-score-multi-field-filters-together/228250/2 "2020-05-14T05:52:35Z")

</div>

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