# Missing results using query\_string wildcard query with rewrite top\_terms\_n

**URL:** <https://discuss.elastic.co/t/missing-results-using-query-string-wildcard-query-with-rewrite-top-terms-n/269680>\
**Category:** Elasticsearch\
**Created:** [April 9, 2021, 8:27am UTC](https://discuss.elastic.co/t/missing-results-using-query-string-wildcard-query-with-rewrite-top-terms-n/269680 "2021-04-09T08:27:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carantunes](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@carantunes](https://discuss.elastic.co/u/carantunes)\
**Post date:** [April 9, 2021, 8:27am UTC](https://discuss.elastic.co/t/missing-results-using-query-string-wildcard-query-with-rewrite-top-terms-n/269680/1 "2021-04-09T08:27:42Z")

</div>

I'm using Elasticsearch version 7.1.1.

I'm experiencing a weird behaviour.  
When using `top_terms_n` in order to obtain a score in wildcard `query_string` queries almost all results are missing. Without `top_terms_n` I obtain 300 results out of 10M, however with the rewrite I obtain 3 results. l Is this behaviour expected? Is there any way I can obtain all the results and still have relevant scores calculated in wildcard matches?

The following query returns about 300 results (out of 10M), without rewrite.

```auto
{
  "query": {
    "query_string": {
      "query": " +_data.cern_id:(ELG-*) +object_type:d +_data.author.full_name:eric"
    }
  }
}

```

However if I search with rewrite `top_terms_n` I only get 3 results back.

```auto
{
  "query": {
    "query_string": {
      "query": " +_data.cern_id:(ELG-*) +object_type:d +_data.author.full_name:eric",
      "rewrite":"top_terms_1000"
    }
  }
}

```

The most confusing part is that if I change the wildcard to be more specific, eg instead of `ELG-*` searching `ELG-GENNET-*`, maintain the remaining queries I obtain more results, 8 instead of 3.

```auto
{
  "query": {
    "query_string": {
      "query": " +_data.cern_id:(ELG-GENNET-*) +object_type:d +_data.author.full_name:eric",
      "rewrite":"top_terms_1000"
    }
  }
}

```

Aditional details: I'm using `dfs_query_then_fetch`.  
I'm setting the mentioned field `cern_id` as a keyword:

```auto
          "cern_id": {
            "type": "keyword",
            "normalizer": "case_accent_normalizer",
            "boost": 5
          },

```

And the mentioned `case_accent_normalizer` normalizer is

```auto
        "case_accent_normalizer": {
          "type": "custom",
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![carantunes](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@carantunes](https://discuss.elastic.co/u/carantunes)\
**Post date:** [May 3, 2021, 8:40am UTC](https://discuss.elastic.co/t/missing-results-using-query-string-wildcard-query-with-rewrite-top-terms-n/269680/2 "2021-05-03T08:40:25Z")

</div>

bump

---

<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 31, 2021, 8:40am UTC](https://discuss.elastic.co/t/missing-results-using-query-string-wildcard-query-with-rewrite-top-terms-n/269680/3 "2021-05-31T08:40:28Z")

</div>

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