# Constant\_score in kibana

**URL:** <https://discuss.elastic.co/t/constant-score-in-kibana/277575>\
**Category:** Kibana\
**Created:** [July 1, 2021, 3:16pm UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575 "2021-07-01T15:16:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [July 1, 2021, 3:16pm UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575/1 "2021-07-01T15:16:50Z")

</div>

Hello,

I'm looking at removing the relevancy score for some of my terms queries to speed them up. I understand how to do that as part of an elasticsearch query but how might I go about setting the constant\_score in a kibana visualization to not deal with relevancy scoring? Does that go in the json input section of the visualization?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 1, 2021, 4:18pm UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575/2 "2021-07-01T16:18:24Z")

</div>

By terms queries do you mean the terms aggregation or the a filter using the terms clause. If it is the latter, you can enter Elasticsearch filter DSL by clicking the "Edit as Query DSL" button in the popover:

 ![Screenshot 2021-07-01 at 18.16.59](https://us1.discourse-cdn.com/elastic/original/3X/3/8/38fe35ab72d7063fe561318be741621a8dde6044.png)  
 ![Screenshot 2021-07-01 at 18.17.03](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1a1e325ea93569c31f3b85f65844746de8f6b7c4.png)

---

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [July 1, 2021, 7:31pm UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575/3 "2021-07-01T19:31:44Z")

</div>

Hello,

Thank you. That is exactly what I was looking for. I figured there was a place to do this since I couldn't see how to do it in the kibana/visualizations. I'm running into a small issue with the query. I'm trying to put this filter in place and I'm getting nothing returned. I'm using the example filter here: [Constant score query | Elasticsearch Guide [7.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html). This is the code I'm using:

```auto
GET /_search
{
  "query": {
    "constant_score": {
      "filter": {
        "term": { "user.id": "kimchy" }
      },
      "boost": 1.2
    }
  }
}

```

I've successfully ran a test that looks like the following:

```auto
GET /_search
{
  "query": {
    "constant_score": {
      "filter": {
        "term": { "filename": "test_audio.mp3" }
      },
      "boost": 1.2
    }
  }
}

```

Where I'm stuck is trying to apply the `constant_score` to every entry in the field `filename`. I attempted to wildcard it:

```auto
GET /_search
{
  "query": {
    "constant_score": {
      "filter": {
        "term": { "filename": "*" }
      },
      "boost": 1.2
    }
  }
}

```

My goal here is to not have to apply any relevancy scoring to the field `filename` Is this possible or is there another method of achieving this? Thank you for your help.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 5, 2021, 7:58am UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575/4 "2021-07-05T07:58:03Z")

</div>

I think I misunderstood what you wanted to do eventually. If you are using Kibana with a query like this:

 ![Screenshot 2021-07-05 at 09.54.43](https://us1.discourse-cdn.com/elastic/original/3X/9/7/97dc88a260ba69c4873134b097240dabc5552218.png)

This is the query that's built behind the scenes:

 ![Screenshot 2021-07-05 at 09.54.56](https://us1.discourse-cdn.com/elastic/original/3X/b/0/b05c2e94fac5399f6b52af40266c8f50d3c95fa2.png)

As you can see, the terms matching (`geo.src` equals `US`) goes into the `filter` of a bool query.

This is what Elasticsearch documentation has to say about `filter`:

> `filter`|The clause (query) must appear in matching documents. However unlike `must` the score of the query will be ignored. Filter clauses are executed in [filter context](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html), meaning that scoring is ignored and clauses are considered for caching.

So as long as your clauses end up in the top level `filter` (which is the case for KQL and filter pills), you don't have to worry about scoring.

---

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [July 7, 2021, 4:29pm UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575/5 "2021-07-07T16:29:33Z")

</div>

Hello,

Thank you for explaining this. You answered my questions and illuminated my understanding of query context vs filter context.

---

<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:** [August 4, 2021, 4:29pm UTC](https://discuss.elastic.co/t/constant-score-in-kibana/277575/6 "2021-08-04T16:29:44Z")

</div>

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