# Different output on query

**URL:** <https://discuss.elastic.co/t/different-output-on-query/265175>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 23, 2021, 8:09am UTC](https://discuss.elastic.co/t/different-output-on-query/265175 "2021-02-23T08:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [February 23, 2021, 8:09am UTC](https://discuss.elastic.co/t/different-output-on-query/265175/1 "2021-02-23T08:09:33Z")

</div>

Hi All,

I have a ES cluster version 6.8 and I am using python lib elasticsearch==7.11.0 and elasticsearch-dsl==7.3.0

I have created the following code

```
index_name = 'central_log_nl'

query = Q('bool',
      must=[
          Q('match', tags="exim_json"),
          Q('range', score={'gte': '15.0', 'lte': '20.0'}),
          Q('range', **{'@timestamp': {'gte': 'now-2h', 'lte': 'now'}}),
      ],
      must_not=[
          Q('match', tags="local_mail_servers"),
      ])

s = Search(using=esClient, index=index_name)
s.query(query)

```

When I execute that query I am getting 2199156482 results which is totally not what I would expect. If I print the query like this:

> print('Main query -\> {}'.format(json.dumps(query.to\_dict())))

I am getting the following output

```auto
Main query -> {"bool": {"must": [{"match": {"tags": "exim_json"}}, {"range": {"score": {"gte": "15.0", "lte": "20.0"}}}, {"range": {"@timestamp": {"gte": "now-2h", "lte": "now"}}}], "must_not": [{"match": {"tags": "local_mail_servers"}}]}}

```

When I execute this query in Kibana -\> dev tools like this:

```
GET central_log_nl/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "tags": "exim_json"
          }
        },
        {
          "range": {
            "score": {
              "gte": 15,
              "lte": 20
            }
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": "now-2h/h",
              "lte": "now"
            }
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "tags": "local_mail_servers"
          }
        }
      ]
    }
  }
}

```

I am getting the following result.

```
{
  "took" : 12,
  "timed_out" : false,
  "_shards" : {
    "total" : 89,
    "successful" : 89,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2149,
    "max_score" : 0.0,
    "hits" : []
  }
}

```

Here I am getting a total of 2149 which is what I would expect.

Can someone please help me to understand what I am doing wrong here?

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [February 24, 2021, 8:47pm UTC](https://discuss.elastic.co/t/different-output-on-query/265175/2 "2021-02-24T20:47:50Z")

</div>

This does not work

> [@pjanzen](#):
>
> `s = Search(using=esClient, index=index_name)`

However, below syntax does work.

> [@pjanzen](#):
>
> `s = Search(using=esClient, index=index_name).query(query)`

---

<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 24, 2021, 8:48pm UTC](https://discuss.elastic.co/t/different-output-on-query/265175/3 "2021-03-24T20:48:14Z")

</div>

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