Variable [_source] is not defined

Hi,
I want to query by a field that's not indexed. A script query should solve my question , query dsl as follows:
GET /_search

{
    "query": {
        "bool" : {
            "must" : {
                "script" : {
                    "script" : {
                        "source": "_source.num > 1",
                        "lang": "painless"
                     }
                }
            }
        }
    }
}

After sending request, I got a error "Variable [_source] is not defined". Need help.

Hi,

You might want to try:

{
    "query": {
        "bool" : {
            "must" : {
                "script" : {
                    "script" : {
                        "source": "doc['num'].value > 1",
                        "lang": "painless"
                     }
                }
            }
        }
    }
}

For further details, please see the documentation on script queries.

@fkelbert, the doc_values of field 'num' was disabled .So I could not use doc['num'].value

@wangqinghuan

Is your problem solved then? If not, what do you currently get? Also, what is the mapping of the field?

it's solved. I modify mapping to enable index and reindex indices.

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