Constant_score in kibana

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?

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:


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. This is the code I'm using:

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

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

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:

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.

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

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

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, 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.

1 Like

Hello,

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