Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search] sorting scripted string fields throws error #72655

Closed
nickofthyme opened this issue Jul 21, 2020 · 4 comments · Fixed by #72681
Closed

[Search] sorting scripted string fields throws error #72655

nickofthyme opened this issue Jul 21, 2020 · 4 comments · Fixed by #72681
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Feature:Search Querying infrastructure in Kibana

Comments

@nickofthyme
Copy link
Contributor

nickofthyme commented Jul 21, 2020

Kibana version:
7.5 and 7.8

Describe the bug:
Sorting a string type scripted field in discover throws an error.

Steps to reproduce:

  1. Add any sample data set
  2. Add a string type scripted field. Something simple like...
return 'Testing';
  1. Go to discover
  2. Add the scripted field to the Selected fields
  3. Try sorting the scripted field column

Expected behavior:
Sorting of scripted string fields

Screenshots (if relevant):
Screen Recording 2020-07-21 at 09 38 AM

Errors in browser console (if relevant):

search_phase_execution_exception
all shards failed

Error: Bad Request
    at Fetch.fetchResponse (http://localhost:5601/zhv/9007199254740991/bundles/core/core.entry.js:57468:13)
    at async interceptResponse (http://localhost:5601/zhv/9007199254740991/bundles/core/core.entry.js:57880:10)
    at async http://localhost:5601/zhv/9007199254740991/bundles/core/core.entry.js:57366:39

Provide logs and/or server output (if relevant):
ES request error

"root_cause" : [
  {
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [
      "return 'Testing';",
      "       ^---- HERE"
    ],
    "script" : "return 'Testing';",
    "lang" : "painless",
    "position" : {
      "offset" : 7,
      "start" : 0,
      "end" : 17
    }
  }
],

Any additional context:

The discovered request appears to be setting the wrong type (i.e. number) for the scripted field which is causing the error. When changed to the correct type (i.e. string), the request is successful.

GET test/_search
{
  "version": true,
  "size": 500,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "_script": {
        "script": {
          "source": "return 'Testing';",
          "lang": "painless"
        },
-        "type": "number",
+        "type": "string",
        "order": "desc"
      }
    }
  ],
  "stored_fields": [
    "*"
  ],
  "script_fields": {
    "scriptTest": {
      "script": {
        "source": "if ( doc['prediction'].value == 3) {\nreturn 'High';\n} else {\nreturn 'Information Only';\n}",
        "lang": "painless"
      }
    },
    "myField": {
      "script": {
        "source": "return 'Testing';",
        "lang": "painless"
      }
    }
  },
  "docvalue_fields": [],
  "_source": {
    "excludes": []
  },
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        }
      ],
      "should": [],
      "must_not": []
    }
  },
  "highlight": {
    "pre_tags": [
      "@kibana-highlighted-field@"
    ],
    "post_tags": [
      "@/kibana-highlighted-field@"
    ],
    "fields": {
      "*": {}
    },
    "fragment_size": 2147483647
  }
}
@nickofthyme nickofthyme added bug Fixes for quality problems that affect the customer experience Feature:Discover Discover Application Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Jul 21, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@nickofthyme nickofthyme changed the title [Discover] sorting scripted fields throws error [Discover] sorting scripted string fields throws error Jul 21, 2020
@nickofthyme nickofthyme self-assigned this Jul 21, 2020
@nickofthyme nickofthyme added Feature:Search Querying infrastructure in Kibana Team:AppArch and removed Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Jul 21, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@nickofthyme nickofthyme removed the Feature:Discover Discover Application label Jul 21, 2020
@nickofthyme nickofthyme changed the title [Discover] sorting scripted string fields throws error [Search] sorting scripted string fields throws error Jul 21, 2020
@edmarmoretti
Copy link

Kibana version:
7.5 and 7.8

Describe the bug:
Sorting a string type scripted field in discover throws an error.

Steps to reproduce:

  1. Add any sample data set
  2. Add a string type scripted field. Something simple like...
return 'Testing';
  1. Go to discover
  2. Add the scripted field to the Selected fields
  3. Try sorting the scripted field column

Expected behavior:
Sorting of scripted string fields

Screenshots (if relevant):
Screen Recording 2020-07-21 at 09 38 AM

Errors in browser console (if relevant):

search_phase_execution_exception
all shards failed

Error: Bad Request
    at Fetch.fetchResponse (http://localhost:5601/zhv/9007199254740991/bundles/core/core.entry.js:57468:13)
    at async interceptResponse (http://localhost:5601/zhv/9007199254740991/bundles/core/core.entry.js:57880:10)
    at async http://localhost:5601/zhv/9007199254740991/bundles/core/core.entry.js:57366:39

Provide logs and/or server output (if relevant):
ES request error

"root_cause" : [
  {
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [
      "return 'Testing';",
      "       ^---- HERE"
    ],
    "script" : "return 'Testing';",
    "lang" : "painless",
    "position" : {
      "offset" : 7,
      "start" : 0,
      "end" : 17
    }
  }
],

Any additional context:

The discovered request appears to be setting the wrong type (i.e. number) for the scripted field which is causing the error. When changed to the correct type (i.e. string), the request is successful.

GET test/_search
{
  "version": true,
  "size": 500,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "_script": {
        "script": {
          "source": "return 'Testing';",
          "lang": "painless"
        },
-        "type": "number",
+        "type": "string",
        "order": "desc"
      }
    }
  ],
  "stored_fields": [
    "*"
  ],
  "script_fields": {
    "scriptTest": {
      "script": {
        "source": "if ( doc['prediction'].value == 3) {\nreturn 'High';\n} else {\nreturn 'Information Only';\n}",
        "lang": "painless"
      }
    },
    "myField": {
      "script": {
        "source": "return 'Testing';",
        "lang": "painless"
      }
    }
  },
  "docvalue_fields": [],
  "_source": {
    "excludes": []
  },
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        }
      ],
      "should": [],
      "must_not": []
    }
  },
  "highlight": {
    "pre_tags": [
      "@kibana-highlighted-field@"
    ],
    "post_tags": [
      "@/kibana-highlighted-field@"
    ],
    "fields": {
      "*": {}
    },
    "fragment_size": 2147483647
  }
}

See in this example that "type" is wrong

image

@nickofthyme
Copy link
Contributor Author

@edmarmoretti Yup, thanks there is a PR up to fix this here #72681

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Search Querying infrastructure in Kibana
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants