Variable [_source] is not defined


(wangqinghuan) #1

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.


(Florian Kelbert) #2

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.


(wangqinghuan) #3

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


(Florian Kelbert) #4

@wangqinghuan

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


(wangqinghuan) #5

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


(system) #6

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