# High build\_scorer value in the query profile result for query wrapped in constant\_score

**URL:** <https://discuss.elastic.co/t/high-build-scorer-value-in-the-query-profile-result-for-query-wrapped-in-constant-score/371976>\
**Category:** Elasticsearch\
**Created:** [December 14, 2024, 3:44am UTC](https://discuss.elastic.co/t/high-build-scorer-value-in-the-query-profile-result-for-query-wrapped-in-constant-score/371976 "2024-12-14T03:44:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lzz118](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@lzz118](https://discuss.elastic.co/u/lzz118)\
**Post date:** [December 14, 2024, 3:44am UTC](https://discuss.elastic.co/t/high-build-scorer-value-in-the-query-profile-result-for-query-wrapped-in-constant-score/371976/1 "2024-12-14T03:44:07Z")

</div>

Hi there,

I used the profiler api to investigate a slow query which is wrapped in constant\_score and filter clause. In the query I used term query to match about 12 keyword terms. I don't want any scoring but in the profiler result, it still shows the most time spent on build\_score. Did I miss anything?

Query definition.

```auto
{
        "profile": true,
  "from": 0,
  "size": 25,
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
 {
                                      "bool": {
                                        "should": [
                                          {
                                            "terms": {
                                              "correlation_uid": [
                                                "CB876463-B4B4-11EF-A16B-005056B95B73",
                                                "8EFE4362-B49D-11EF-A16B-005056B9AC67",
                                                "81BA6A1C-B431-11EF-A16B-005056B9AC67",
                                                "7097C191-B438-11EF-A16B-005056B95B73",
                                                "81BA6FF2-B431-11EF-A16B-005056B9AC67",
                                                "8EFE3B02-B49D-11EF-A16B-005056B9AC67",
                                                "FB710A75-B4D1-11EF-A16B-005056B95B73",
                                                "7097AD4B-B438-11EF-A16B-005056B95B73",
                                                "F71B6CAF-B458-11EF-A16B-005056B95B73",
                                                "E56E8452-B4C1-11EF-A166-005056A581D7",
                                                "81BA7345-B431-11EF-A16B-005056B9AC67",
                                                "673500D9-B4AB-11EF-A165-005056A50E79"
                                              ],
                                              "boost": 1.0
                                            }
                                          }
                                        ],
                                        "adjust_pure_negative": true,
                                        "boost": 1.0
                                      }
                                    }
...

```

Profiler result

```auto
{
                                                                        "type": "ConstantScoreQuery",
                                                                        "description": "ConstantScore(correlation_uid:673500d9-b4ab-11ef-a165-005056a50e79 correlation_uid:7097ad4b-b438-11ef-a16b-005056b95b73 correlation_uid:7097c191-b438-11ef-a16b-005056b95b73 correlation_uid:81ba6a1c-b431-11ef-a16b-005056b9ac67 correlation_uid:81ba6ff2-b431-11ef-a16b-005056b9ac67 correlation_uid:81ba7345-b431-11ef-a16b-005056b9ac67 correlation_uid:8efe3b02-b49d-11ef-a16b-005056b9ac67 correlation_uid:8efe4362-b49d-11ef-a16b-005056b9ac67 correlation_uid:cb876463-b4b4-11ef-a16b-005056b95b73 correlation_uid:e56e8452-b4c1-11ef-a166-005056a581d7 correlation_uid:f71b6caf-b458-11ef-a16b-005056b95b73 correlation_uid:fb710a75-b4d1-11ef-a16b-005056b95b73)",
                                                                        "time_in_nanos": 1326915878,
                                                                        "breakdown":
                                                                        {
                                                                            "set_min_competitive_score_count": 0,
                                                                            "match_count": 0,
                                                                            "shallow_advance_count": 0,
                                                                            "set_min_competitive_score": 0,
                                                                            "next_doc": 0,
                                                                            "match": 0,
                                                                            "next_doc_count": 0,
                                                                            "score_count": 0,
                                                                            "compute_max_score_count": 0,
                                                                            "compute_max_score": 0,
                                                                            "advance": 0,
                                                                            "advance_count": 0,
                                                                            "score": 0,
                                                                            "build_scorer_count": 33,
                                                                            "create_weight": 9362,
                                                                            "shallow_advance": 0,
                                                                            "create_weight_count": 1,
                                                                            "build_scorer": 1326906516
                                                                        },
                                                                        "children":
                                                                        [
                                                                            {
                                                                                "type": "BooleanQuery",
                                                                                "description": "correlation_uid:673500d9-b4ab-11ef-a165-005056a50e79 correlation_uid:7097ad4b-b438-11ef-a16b-005056b95b73 correlation_uid:7097c191-b438-11ef-a16b-005056b95b73 correlation_uid:81ba6a1c-b431-11ef-a16b-005056b9ac67 correlation_uid:81ba6ff2-b431-11ef-a16b-005056b9ac67 correlation_uid:81ba7345-b431-11ef-a16b-005056b9ac67 correlation_uid:8efe3b02-b49d-11ef-a16b-005056b9ac67 correlation_uid:8efe4362-b49d-11ef-a16b-005056b9ac67 correlation_uid:cb876463-b4b4-11ef-a16b-005056b95b73 correlation_uid:e56e8452-b4c1-11ef-a166-005056a581d7 correlation_uid:f71b6caf-b458-11ef-a16b-005056b95b73 correlation_uid:fb710a75-b4d1-11ef-a16b-005056b95b73",
                                                                                "time_in_nanos": 1326909240,
                                                                                "breakdown":
                                                                                {
                                                                                    "set_min_competitive_score_count": 0,
                                                                                    "match_count": 0,
                                                                                    "shallow_advance_count": 0,
                                                                                    "set_min_competitive_score": 0,
                                                                                    "next_doc": 0,
                                                                                    "match": 0,
                                                                                    "next_doc_count": 0,
                                                                                    "score_count": 0,
                                                                                    "compute_max_score_count": 0,
                                                                                    "compute_max_score": 0,
                                                                                    "advance": 0,
                                                                                    "advance_count": 0,
                                                                                    "score": 0,
                                                                                    "build_scorer_count": 33,
                                                                                    "create_weight": 8855,
                                                                                    "shallow_advance": 0,
                                                                                    "create_weight_count": 1,
                                                                                    "build_scorer": 1326900385
                                                                                },
                                                                                "children":
                                                                                [
                                                                                    {
                                                                                        "type": "TermQuery",
                                                                                        "description": "correlation_uid:673500d9-b4ab-11ef-a165-005056a50e79",
                                                                                        "time_in_nanos": 377166903,
                                                                                        "breakdown":
                                                                                        {
                                                                                            "set_min_competitive_score_count": 0,
                                                                                            "match_count": 0,
                                                                                            "shallow_advance_count": 0,
                                                                                            "set_min_competitive_score": 0,
                                                                                            "next_doc": 0,
                                                                                            "match": 0,
                                                                                            "next_doc_count": 0,
                                                                                            "score_count": 0,
                                                                                            "compute_max_score_count": 0,
                                                                                            "compute_max_score": 0,
                                                                                            "advance": 0,
                                                                                            "advance_count": 0,
                                                                                            "score": 0,
                                                                                            "build_scorer_count": 33,
                                                                                            "create_weight": 1062,
                                                                                            "shallow_advance": 0,
                                                                                            "create_weight_count": 1,
                                                                                            "build_scorer": 377165841
                                                                                        }
                                                                                    },
                                                                                    ,
                                                                                    {
                                                                                        "type": "TermQuery",
                                                                                        "description": "correlation_uid:7097ad4b-b438-11ef-a16b-005056b95b73",
                                                                                        "time_in_nanos": 184412276,
                                                                                        "breakdown":
                                                                                        {
                                                                                            "set_min_competitive_score_count": 0,
                                                                                            "match_count": 0,
                                                                                            "shallow_advance_count": 0,
                                                                                            "set_min_competitive_score": 0,
                                                                                            "next_doc": 0,
                                                                                            "match": 0,
                                                                                            "next_doc_count": 0,
                                                                                            "score_count": 0,
                                                                                            "compute_max_score_count": 0,
                                                                                            "compute_max_score": 0,
                                                                                            "advance": 0,
                                                                                            "advance_count": 0,
                                                                                            "score": 0,
                                                                                            "build_scorer_count": 33,
                                                                                            "create_weight": 490,
                                                                                            "shallow_advance": 0,
                                                                                            "create_weight_count": 1,
                                                                                            "build_scorer": 184411786
                                                                                        }
                                                                                    },
...
...

```

---

<div class="post-metadata">

**Author:** ![lzz118](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@lzz118](https://discuss.elastic.co/u/lzz118)\
**Post date:** [December 14, 2024, 4:58am UTC](https://discuss.elastic.co/t/high-build-scorer-value-in-the-query-profile-result-for-query-wrapped-in-constant-score/371976/2 "2024-12-14T04:58:50Z")

</div>

> [@lzz118](#):
>
> `build_scorer_count`

One way of speeding up this query I could think of is to force merge the segments to 1 for the indices being searched.

Any other suggestions? I also tried to replace the constant\_score with just bool, removing the boost as well as adjust\_pure\_negative , not much different in performance.

```auto
query": {
    "bool": {
      "filter": {

```

---

<div class="post-metadata">

**Author:** ![lzz118](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@lzz118](https://discuss.elastic.co/u/lzz118)\
**Post date:** [December 30, 2024, 7:50pm UTC](https://discuss.elastic.co/t/high-build-scorer-value-in-the-query-profile-result-for-query-wrapped-in-constant-score/371976/3 "2024-12-30T19:50:39Z")

</div>

Surprised that no one has seen the issue.
