# Filter request and score

**URL:** <https://discuss.elastic.co/t/filter-request-and-score/153554>\
**Category:** Elasticsearch\
**Created:** [October 23, 2018, 9:21am UTC](https://discuss.elastic.co/t/filter-request-and-score/153554 "2018-10-23T09:21:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HugoP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hugop/32/43435_2.png) [@HugoP](https://discuss.elastic.co/u/HugoP)\
**Post date:** [October 23, 2018, 9:21am UTC](https://discuss.elastic.co/t/filter-request-and-score/153554/1 "2018-10-23T09:21:08Z")

</div>

Hi all,

I was running some test to understand the filter notion in ES:

```
POST /index_test/1
{
  "firstname":"John",
  "lastname": "Doe"
  
}

GET /index_test/_search
{
  "query":{
    "term": {
        "firstname.keyword": "John"
      }
  }
}

```

I don't understand why there is a score in the result set if I am using a filter clause:

```
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
  {
    "_index": "index_test",
    "_type": "1",
    "_id": "BfswoGYBR1LGPYDH8oD_",
    "_score": 0.2876821,
    "_source": {
      "firstname": "John",
      "lastname": "Doe"
    }
  }
]
}
```

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [October 23, 2018, 10:19am UTC](https://discuss.elastic.co/t/filter-request-and-score/153554/2 "2018-10-23T10:19:18Z")

</div>

The filter clause is missing in your query :

```
GET /index_test/_search
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "firstname.keyword": "John"
        }
      }
    }
  }
}

```

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html)

---

<div class="post-metadata">

**Author:** ![HugoP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hugop/32/43435_2.png) [@HugoP](https://discuss.elastic.co/u/HugoP)\
**Post date:** [October 23, 2018, 11:56am UTC](https://discuss.elastic.co/t/filter-request-and-score/153554/3 "2018-10-23T11:56:05Z")

</div>

Ok ! I have another question related to the scoring of filter results.

My mapping is the following:

```
{
  "index_test": {
    "mappings": {
      "type1": {
        "properties": {
          "age": {
            "type": "long"
          },
          "firstname": {
            "type": "keyword"
          },
          "lastname": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

```

How can the following request score the hits while the lastname type is keyword ?

```
GET /index_test/_search
{
  "query":{
    "term": {
        "firstname": "John"
      }
  }
}
```

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [October 23, 2018, 1:24pm UTC](https://discuss.elastic.co/t/filter-request-and-score/153554/4 "2018-10-23T13:24:01Z")

</div>

It doesn't matter the field type, you are in a query context, so you will get a score for the documents returned by this query. The filter context implies a `filter` clause.

The scoring formula will give a score to a field even if it's a keyword. The formula based on the TF/IDF takes in account multiple parameters. (ex. : the number of documents you have on your index.)

[https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html)

---

<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:** [November 20, 2018, 1:24pm UTC](https://discuss.elastic.co/t/filter-request-and-score/153554/5 "2018-11-20T13:24:02Z")

</div>

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