# Use of script fields?

**URL:** <https://discuss.elastic.co/t/use-of-script-fields/100668>\
**Category:** Kibana\
**Created:** [September 15, 2017, 10:03am UTC](https://discuss.elastic.co/t/use-of-script-fields/100668 "2017-09-15T10:03:01Z")\
**Posts on this page:** 6\
**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:** [September 15, 2017, 10:03am UTC](https://discuss.elastic.co/t/use-of-script-fields/100668/1 "2017-09-15T10:03:01Z")

</div>

Good morning!

I read the documentation about these types of fields but I don't know if is possible what I want do.

Now when I do the search I get the values like these:

```
   {
      "id": "41526940A",
      "sex": "H",
      "prov": "GI",
      "provincia": "GIRONA",
      "op": 10
    }

```

And I created one script field with this expresion doc['op'].value\*2. My intention is that when I do the search I want this format of results:

```
   {
      "id": "41526940A",
      "sex": "H",
      "prov": "GI",
      "provincia": "GIRONA",
      "op": 10,
      "scfield": 20
    }

```

Will can I do my purpose with script fields?

Thanks for all!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 15, 2017, 10:04am UTC](https://discuss.elastic.co/t/use-of-script-fields/100668/2 "2017-09-15T10:04:52Z")

</div>

Yes, it will do that.

---

<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:** [September 15, 2017, 1:10pm UTC](https://discuss.elastic.co/t/use-of-script-fields/100668/3 "2017-09-15T13:10:38Z")

</div>

Hi!

First of all thanks for the answer.

I did a new index to prove:

```
"hits": [
  {
    "_index": "prova",
    "_type": "type",
    "_id": "AV6FAf4gTEbznHb_Ak4g",
    "_score": 1,
    "_source": {
      "id": "1",
      "opinion": "25"
    }
  }

```

And my script field is:

scProva expression doc['opinion'].value\*2 Number

Now I see that this field exists in the "discover" of kibana. But how can I do that with this search:

GET /prova/\_search

Get the structure that appears in the "discover"?

{  
"\_index": "prova",  
"\_type": "type",  
"\_id": "AV6FAf4gTEbznHb\_Ak4g",  
"\_score": 1,  
"\_source": {  
"id": "1",  
"opinion": "25"  
},  
"fields": {  
"scProva": [  
50  
]  
}  
}

Thanks!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 16, 2017, 6:42am UTC](https://discuss.elastic.co/t/use-of-script-fields/100668/4 "2017-09-16T06:42:28Z")

</div>

Please use code formatting on everything, as it can hide syntax that is important.

Is that the actual script expression you are using?

---

<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:** [September 17, 2017, 6:41pm UTC](https://discuss.elastic.co/t/use-of-script-fields/100668/5 "2017-09-17T18:41:32Z")

</div>

My script is of type expression with this code:

doc['opinion'].value\*2

I think that the script is correct because in Kibana I can see this value:

"\_index": "prova",  
"\_type": "type",  
"\_id": "AV6FAf4gTEbznHb\_Ak4g",  
"\_score": 1,  
"\_source": {  
"id": "1",  
"opinion": "25"  
},  
"fields": {  
"scProva": [  
50  
]  
}  
}

But I want know how can I can get this JSON structure, because when I do the search I only can obtain the fields inside \_source.

![Json](https://us1.discourse-cdn.com/elastic/original/3X/f/0/f0f3999507e1c467c4cfdbf5a886242158a4cc52.png)

 ![Search](https://us1.discourse-cdn.com/elastic/original/3X/d/2/d21a3220c07de6e53f0f9c49cd7e9c0a9288b165.png)

Thanks for all 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:** [October 15, 2017, 6:42pm UTC](https://discuss.elastic.co/t/use-of-script-fields/100668/6 "2017-10-15T18:42:22Z")

</div>

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