# Runtime fields cannot be used when querying ？

**URL:** <https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599>\
**Category:** Elasticsearch\
**Created:** [July 14, 2022, 3:51am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599 "2022-07-14T03:51:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lnsane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lnsane/32/108288_2.png) [@lnsane](https://discuss.elastic.co/u/lnsane)\
**Post date:** [July 14, 2022, 3:51am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/1 "2022-07-14T03:51:29Z")

</div>

index "user"

user doc matedata

```json
{
"userName": "admin"
"age": 1
}

```

i'm add runtime fields name "userAge"

scipt

`emit(doc['userName'].value + doc['age'].value)`

Why can't I use the userAge field in my program ？

my using docker create eslatic

```auto
version: '3.8'

services:
  elastic-search:
    image: elasticsearch:7.13.4
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      discovery.type: single-node

  kibama:
    image: kibana:7.13.4
    ports:
      - "5601:5601"
    depends_on:
      - elastic-search
    environment:
      ELASTICSEARCH_URL: http://elastic-search:9200
      ELASTICSEARCH_HOSTS: '["http://elastic-search:9200"]'
      I18N_LOCALE: zh-CN

```

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [July 17, 2022, 6:07am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/2 "2022-07-17T06:07:37Z")

</div>

What do you mean by "I can't use the userAge field"?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 17, 2022, 5:17pm UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/3 "2022-07-17T17:17:46Z")

</div>

Hi @lnsane Welcome to the community.

Exactly how did you add the runtime field?

Please show us the entire mapping not just a snippet

`GET /user`

Please show us the query you are trying to run.

> [@lnsane](#):
>
> Why can't I use the userAge field in my program ？

Please provide more details what this means

Did you add the runtime field to the Kibana -\> Stack Management -\> Data View / Mapping  
or

Did you add the runtime field directly to the index mapping as shown [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-mapping-fields.html#runtime-mapping-fields)

If you added it to the index mapping the field will be available for search .. if you added it only to the Data View the runtime field will not be available for search

---

<div class="post-metadata">

**Author:** ![lnsane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lnsane/32/108288_2.png) [@lnsane](https://discuss.elastic.co/u/lnsane)\
**Post date:** [July 18, 2022, 1:41am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/4 "2022-07-18T01:41:41Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/a/f/afef1de3815cdcbfa35064fdd73f32d74ecfd29c.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/e/4ef58208b529c41030f969f6cb79c3cb8458d9b6.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/05ff1d50ff1d8d9a5827dee589f9be2afb6c0a83.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/a/9a4d8dfc30693ba5cdb0f9f3d1e587bb500dede4.png)  
Please tell me how to query data using userAge index ？

---

<div class="post-metadata">

**Author:** ![lnsane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lnsane/32/108288_2.png) [@lnsane](https://discuss.elastic.co/u/lnsane)\
**Post date:** [July 18, 2022, 1:43am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/5 "2022-07-18T01:43:21Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/8/78ab17acb8f8e4dfad468f440145623d7fb71ceb.png)

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 18, 2022, 2:36am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/6 "2022-07-18T02:36:25Z")

</div>

You appear to have added the runtime field `userAge` through the Data View and thus you can not use that field in a search

You need to follow these instructions and actually add the runtime field into the mapping so you can use it in a search.

That is the only way you will be able to use it in a search.

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

---

<div class="post-metadata">

**Author:** ![lnsane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lnsane/32/108288_2.png) [@lnsane](https://discuss.elastic.co/u/lnsane)\
**Post date:** [July 25, 2022, 1:12am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/7 "2022-07-25T01:12:10Z")

</div>

thank you！

---

<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 22, 2022, 1:12am UTC](https://discuss.elastic.co/t/runtime-fields-cannot-be-used-when-querying/309599/8 "2022-08-22T01:12:15Z")

</div>

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