Accessing _source from script search in 5.0


(Nicolas Garfinkiel) #1

Hey all, I think I'm going crazy... Could someone tell me why I fail to access the _source field on this query?

{
  "size": 0,
  "query": {
    "constant_score": {
      "filter": {
        "script": {
          "script": {
            "inline": "_source.lab_tests.length > 0"
          }
        }
      }
    }
  }
}

I get...

{
    "type": "script_exception",
    "reason": "compile error",
    "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "Variable [_source] is not defined."
 }

Thank you in advance


Access Source While Making Search Script
Getting index status from monitoring data index .monitoring-es-*
(Nik Everett) #2

_source isn't supported in Painless.... You can get it with groovy still.

It isn't supported because it is so, so, so much slowed than loading fields from doc values. Like several orders of magnitude slower in most cases.


(Nicolas Garfinkiel) #3

I see... Didn't see it in the docs though. Is it there?

Anyways, I understand doc_values access is way faster than _source, that most use cases deal with values already in doc_values, and some features require hard limits for safety's sake.

What I don't understand is the call for blocking a feature because it is not as performant as another feature. Painless works inline as is, and it is very useful for ad_hoc querying. It is stupid to store a groovy query for a quick question and unsafe to allow it to run inline. I needed a quick answer from a field that is not indexed because I don't need it at query time for my application.

Why don't let the user worry about the consequences? In a SQL database you can easily blow it by issuing a simple SELECT, but you can issue it anyways.

My two cents, and thanks alot nick BTW.

Cheers.


(system) #4