Runtime fields cannot be used when querying ?

index "user"

user doc matedata

{
"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

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

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

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.

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

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





Please tell me how to query data using userAge index ?

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.

1 Like

thank you!