Hey, I wanted to know what is the difference between defining runtime_field in mapping v/s and doing so in the query itself.
For this, I tried running the following requests to observe if there occurs any changes in internal calculation by observing the profile section of the output, but seems like I am unlucky. The profile section does not tell anything specific to the calculation of the runtime field and seems like the sample data is not large enough to produce any significant difference in the timings of the search results over the indexes.
POST _reindex
{
"source": {"index": "kibana_sample_data_ecommerce"},
"dest": {"index": "sample"}
}
GET /kibana_sample_data_ecommerce/_search
{
"profile": true,
"explain": true
}
GET /kibana_sample_data_ecommerce/_search
{
"_source": false,
"fields": [
"*"
],
"profile": true,
"explain": true
}
PUT /sample/_mapping
{
"runtime": {
"taxful_total_price": {
"type": "long"
},
"taxless_total_price": {
"type": "long"
},
"tax_value": {
"type": "long",
"script": {
"source": """
emit(doc['taxful_total_price'].value - doc['taxless_total_price'].value);
"""
}
}
}
}
GET /sample/_search
{
"_source": false,
"profile": true,
"explain": true
}
GET /sample/_search
{
"profile": true,
"explain": true
}
GET /sample/_search
{
"fields": [
"*"
],
"_source": false,
"profile": true,
"explain": true
}
GET /kibana_sample_data_ecommerce/_search
{
"profile": true,
"query": {
"bool": {
"filter": [
{
"range": {
"order_date": {
"gte": "2023-09-04T23:45:36.000Z"
}
}
}
]
}
},
"runtime_mappings": {
"taxful_total_price": {
"type": "long"
},
"taxless_total_price": {
"type": "long"
},
"tax_value": {
"type": "long",
"script": {
"source": """
emit(doc['taxful_total_price'].value - doc['taxless_total_price'].value);
"""
}
}
},
"fields": [
"*"
],
"_source": false
}
Can anyone tell if there is any difference between the two methods in terms of performance and also the what is the best-practice when creating these run-time fields.