# Field Type: token\_count - major query speed differences on range vs. term query

**URL:** <https://discuss.elastic.co/t/field-type-token-count-major-query-speed-differences-on-range-vs-term-query/354466>\
**Category:** Elasticsearch\
**Created:** [February 29, 2024, 4:37pm UTC](https://discuss.elastic.co/t/field-type-token-count-major-query-speed-differences-on-range-vs-term-query/354466 "2024-02-29T16:37:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 29, 2024, 4:37pm UTC](https://discuss.elastic.co/t/field-type-token-count-major-query-speed-differences-on-range-vs-term-query/354466/1 "2024-02-29T16:37:17Z")

</div>

Hey,

I've been running a query that is doing a `term` query against a field mapped as `token_count`. This query has very different speeds depending if I use a term query like this:

```json
{ "term" : { "token_count_field": 1 }

```

vs

```json
{ "range" : { "token_count_field": { "lte": 1, "gte": 1} }

```

The latter one is much faster. A sample query that runs around 30ms now is down to 15ms by just using the range query.

The profiler shows, that the is a `PointRangeQuery` on the token count field, where as the fast query is a `IndexOrDocValuesQuery`.

Am I missing something or should that be the default for a term query for the token count filter?

This is on 7.17.18.

--Alex

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 29, 2024, 4:52pm UTC](https://discuss.elastic.co/t/field-type-token-count-major-query-speed-differences-on-range-vs-term-query/354466/2 "2024-02-29T16:52:39Z")

</div>

Here is a sample to reproduce, happens also on 8.11.4

```auto
DELETE test 

PUT test/
{
  "mappings": {
    "properties": {
      "token_count" : {
        "type": "token_count",
        "analyzer": "standard"
      }
    }
  }
}

PUT test/_doc/21refresh
{
  "token_count" : "foo bar baz"
}

GET test/_search
{
  "profile": true, 
  "query": {
    "term": {
      "token_count": {
        "value": "3"
      }
    }
  }
}

GET test/_search
{
  "profile": true, 
  "query": {
    "range": {
      "token_count": {
        "gte": "3", "lte" : 3
      }
    }
  }
}

```

---

<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:** [March 28, 2024, 4:52pm UTC](https://discuss.elastic.co/t/field-type-token-count-major-query-speed-differences-on-range-vs-term-query/354466/3 "2024-03-28T16:52:59Z")

</div>

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