Search the ScriptFields

Hello!

How can I get the value of a script field? Using kibana I can get the value:

image

But I don't know if is possible get this field using the "dev tools" of Kibana, like:

GET prova/_search

Prova = index

Thanks for the help!

Here is a link that can provide some information.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html

Kibana scripted fields simply store the script and inject it into the ES query for you.

First of all Thanks for the answer.

I thought that when I created the script field in Kibana, I didn't need specify again the script in the search.

Now I can get the scriptfield:

GET /prova/_search
{
"script_fields": {
"a": {
"script": "doc['opinion'].value*2"
}
}

But I only can get the script value, not the other fields of the index, how can I get the fields of the index and the scriptField please?

Search with fields
---> GET prova/_search

Search with scriptfield
----->

GET /prova/_search
{
"script_fields": {
"a": {
"script": "doc['opinion'].value*2"
}
}

}

Thanks for all the help!!

This one took a little playing around for me too.

If you include a "_source" property in your search object, it returns all of your fields.

ie:

POST script-field-test/_search
{
  "_source": {},
  "script_fields" : {
      "age-in-a-millennium" : {
          "script" : "doc['age'].value + 1000"
      }
  }
}

How I found this:
I added a scripted field in Kibana, and then navigated to Discover. I then watched the Network tab in my browser developer tools and examined the request payload for the _msearch request I found there.

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