Use of script fields?

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!

Yes, it will do that.

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!

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

Is that the actual script expression you are using?

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

Thanks for all the help!

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