# Searching with runtime, without mapping with runtime

**URL:** <https://discuss.elastic.co/t/searching-with-runtime-without-mapping-with-runtime/339696>\
**Category:** Elasticsearch\
**Tags:** painless, runtime-fields\
**Created:** [July 31, 2023, 1:11pm UTC](https://discuss.elastic.co/t/searching-with-runtime-without-mapping-with-runtime/339696 "2023-07-31T13:11:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [July 31, 2023, 1:11pm UTC](https://discuss.elastic.co/t/searching-with-runtime-without-mapping-with-runtime/339696/1 "2023-07-31T13:11:12Z")

</div>

hello , I am trying to learn runtime .  
it uses in the script the painless language , It wold be nice to I understand this language , that I could test it before mapping .  
the way to test it before mapping it is search with runtime .  
here it has one example -

> **[Map a runtime field | Elasticsearch Guide \[8.9\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-mapping-fields.html)**

```auto

PUT my-index-000002-test/
{
  "mappings": {
    "runtime": {
      "day_of_week": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
        }
      }
    },
    "properties": {
      "@timestamp": {"type": "date"}
    }
  }
}

GET my-index-000002-test/_mapping

POST my-index-000002-test/_bulk?refresh=true
{"index":{}}
{"@timestamp":1516729294000,"model_number":"QVKC92Q","measures":{"voltage":"5.2","start": "300","end":"8675309"}}
{"index":{}}
{"@timestamp":1516642894000,"model_number":"QVKC92Q","measures":{"voltage":"5.8","start": "300","end":"8675309"}}
{"index":{}}
{"@timestamp":1516556494000,"model_number":"QVKC92Q","measures":{"voltage":"5.1","start": "300","end":"8675309"}}
{"index":{}}
{"@timestamp":1516470094000,"model_number":"QVKC92Q","measures":{"voltage":"5.6","start": "300","end":"8675309"}}
{"index":{}}
{"@timestamp":1516383694000,"model_number":"HG537PU","measures":{"voltage":"4.2","start": "400","end":"8625309"}}
{"index":{}}
{"@timestamp":1516297294000,"model_number":"HG537PU","measures":{"voltage":"4.0","start": "400","end":"8625309"}}

GET my-index-000002-test/_search
{
  "query": {
    "match_all": {}
  },
   "fields" : ["day_of_week"]
}

```

this worked for me .  
it returns -

```auto
"hits": [
      {
        "_index": "my-index-000002-test",
        "_id": "pEH4q4kB6LNnmdzdEkwe",
        "_score": 1,
        "_source": {
          "@timestamp": 1516729294000,
          "model_number": "QVKC92Q",
          "measures": {
            "voltage": "5.2",
            "start": "300",
            "end": "8675309"
          }
        },
        "fields": {
          "day_of_week": [
            "Tuesday"
          ]
        }
      },
      {
        "_index": "my-index-000002-test",
        "_id": "pUH4q4kB6LNnmdzdEkwe",
        "_score": 1,
        "_source": {
          "@timestamp": 1516642894000,
          "model_number": "QVKC92Q",
          "measures": {
            "voltage": "5.8",
            "start": "300",
            "end": "8675309"
          }
        },
        "fields": {
          "day_of_week": [
            "Monday"
          ]
        }
      },

```

NOW, I am trying to search with runtime , without mapping with runtime .  
this is important to I test the Painless Script .  
So , I did like that -

```auto
GET my-index-000002-test/_search
{
  "runtime_mappings": {
    "day_of_week": {
      "type": "keyword",
      "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
    }
  },
  "query": {
     "match_all": {}
  },
  "fields" : ["day_of_week"]
}

```

It is the same script that I used to mapping , and after search .  
but it gave me this error -

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "unknown parameter [source] on runtime field [day_of_week] of type [keyword]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "my-index-000002-test",
        "node": "d8DCCAzDQGCLFPA7rX5QSQ",
        "reason": {
          "type": "mapper_parsing_exception",
          "reason": "unknown parameter [source] on runtime field [day_of_week] of type [keyword]"
        }
      }
    ]
  },
  "status": 400
}

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [July 31, 2023, 1:31pm UTC](https://discuss.elastic.co/t/searching-with-runtime-without-mapping-with-runtime/339696/2 "2023-07-31T13:31:14Z")

</div>

> [@Murilo\_Livorato](#):
>
> It is the same script that I used to mapping

It is not, in the mapping you used:

```auto
      "day_of_week": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
        }
      }

```

But in your search you used:

```auto
    "day_of_week": {
      "type": "keyword",
      "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
    }
  }

```

Which is the issue, the `source` needs to be inside the `script` object as you can see in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html#runtime-search-request).

---

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [July 31, 2023, 1:48pm UTC](https://discuss.elastic.co/t/searching-with-runtime-without-mapping-with-runtime/339696/3 "2023-07-31T13:48:55Z")

</div>

thanks, it works

---

<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:** [August 28, 2023, 1:49pm UTC](https://discuss.elastic.co/t/searching-with-runtime-without-mapping-with-runtime/339696/4 "2023-08-28T13:49:16Z")

</div>

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