# Script field

**URL:** <https://discuss.elastic.co/t/script-field/345827>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 26, 2023, 1:42pm UTC](https://discuss.elastic.co/t/script-field/345827 "2023-10-26T13:42:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kirtash](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@Kirtash](https://discuss.elastic.co/u/Kirtash)\
**Post date:** [October 26, 2023, 1:42pm UTC](https://discuss.elastic.co/t/script-field/345827/1 "2023-10-26T13:42:49Z")

</div>

Good morning,

I'm beginning to work with scripting fields and I have doubts and problems. I have created this index:

```auto
POST /sergi-script/_doc/1
{
  "access": "2023-10-26T00:00:00"
}

POST /sergi-script/_doc/2
{
  "access": "2023-10-26T00:00:00",
  "photo": true
}

```

And now my intention is create an script fields using this info:

1. Get a boolean when the access field is befoire than a date:

```auto
GET /sergi-script/_search
{
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "antes": {
      "script": {
        "lang": "painless", 
        "source": "doc['access'].value.isBefore(params['date1'])",
        "params": {
          "date1": "2023-01-01T00:00:00"
        }
      }
    }
  }
}

```

I have an error but I don't understand the reason ☹

1. Is it possible get a boolean field that returns true (when the field photo exists) otherwise false?

Thanks for the help

---

<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 23, 2023, 1:43pm UTC](https://discuss.elastic.co/t/script-field/345827/2 "2023-11-23T13:43:35Z")

</div>

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