I have a personal messages system. Each message contains MEMBERS nested object
"MEMBERS" : {
"type" : "nested",
"properties" : {
"ID" : {
"type" : "long"
},
"LEFT" : {
"type" : "long"
},
"NICK" : {
"type" : "keyword"
},
"READ" : {
"type" : "long"
}
}
},
For system notifications MEMBERS is an array of one item - destination user. The goal is to exclude system notifications ( display only messages with MEMBERS.size()>1 ). I'm trying to use the following query with script filter but the result is empty. It also does not work even for doc.containsKey("MEMBERS") like there is no document containing that field ( there are 1000x of them )
PHP code:
$q[ 'query' ] = array( 'bool' => array(
'must' => array(
'nested' => array(
'path' => 'MEMBERS',
'query' => array(
'bool' => array(
'must' => array(
'term' => array(
'MEMBERS.ID' => $uid
)
),
'filter' => array(
'script' => array(
'script' => array(
'inline' => 'if( doc.containsKey("MEMBERS") && doc["MEMBERS"].size()>1 ) return true'
)
)
)
)
)
),
)
));
Please advise.
I'm using v5.1.x