# Why only one of these queries returns a record?

**URL:** <https://discuss.elastic.co/t/why-only-one-of-these-queries-returns-a-record/287311>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 21, 2021, 11:48am UTC](https://discuss.elastic.co/t/why-only-one-of-these-queries-returns-a-record/287311 "2021-10-21T11:48:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stexxen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stexxen/32/68327_2.png) [@stexxen](https://discuss.elastic.co/u/stexxen)\
**Post date:** [October 21, 2021, 11:48am UTC](https://discuss.elastic.co/t/why-only-one-of-these-queries-returns-a-record/287311/1 "2021-10-21T11:48:13Z")

</div>

Could someone explain why these queries are not returning the same response?

This first query using script returns no records

```auto
GET /ind1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": """
              doc['event_id'] == '10092831599'
              """
          }
        }
      ]
    }
  }
}

```

Whereas this query returns 1 record as expected.

```auto
GET /ind1/_search
{
  "query": {
    "term": {
      "event_id": "10092831599"
    }
  }
}

```

Why is the script query not working in the same way as the term query? I have tried using single-quotes, double-quotes, using as a param value, but always the same result.... no records found...

The `event_id` field is mapped as

```auto
"event_id" : {
  "type" : "keyword"
},

```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 21, 2021, 12:02pm UTC](https://discuss.elastic.co/t/why-only-one-of-these-queries-returns-a-record/287311/2 "2021-10-21T12:02:56Z")

</div>

The script syntax is `doc['event_id'].value`. It's and old syntax who's reasoning is historical.

---

<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:** [November 18, 2021, 12:03pm UTC](https://discuss.elastic.co/t/why-only-one-of-these-queries-returns-a-record/287311/3 "2021-11-18T12:03:28Z")

</div>

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