This is my elasticsearch query. I am trying to get all the documents which meets the condition where if job_id
is 1 then get documents which has sourced = 0
else if job_id
is not 1 then get documents with sourced = 1
.
But it returns all the documents.
[
'script' =>
['script' =>
[
'lang' => 'painless',
'source' => "(doc['job_id'].size() > 0 && doc['job_id'].value !== params.jid) || (doc['job_id'].size() > 0 && doc['job_id'].value == params.jid && doc['sourced'].value == 0)",
'params' => ['jid' => 1]
]
]
]
Mapping for referred fields
"job_id" : {
"type" : "long"
},
"sourced" : {
"type" : "byte"
},
Each document is evaluated by the inline script.
An example (base on your mappings):
Insert documents
Search Query
Your usage
Results
Hope this helps