I am trying to add a must_not
clause to my search using Laravel Scout and babenkoivan/scout-elasticsearch-driver
on top of Elasticsearch.
The idea is to exclude all results where the sold
field either has a timestamp of more than 14 days, or is greater than zero.
I can't seem to get the correct syntax however, and there is no documentation on how to do this on the package repo. I tried formatting it like it is in the Elasticsearch docs but this is not correct.
Here is the set of rules:
public function buildQueryPayload()
{
$query = $this->builder->query;
return [
'must' => [
'query_string' => [
'query' => $query,
],
],
'must_not' => [
'term' => [
'visible' => 0
],
'range' => [
'sold' => [
'lte' => time() - 1209601, // 14 days ago plus 1 second
'gte' => 0
]
]
],
'should' => [
...
],
];
}
Currently I get a Elasticsearch\Common\Exceptions\BadRequest400Exception
error.
Here is the error complaining about the syntax:
{
"error":{
"root_cause":[
{
"type":"parsing_exception",
"reason":"[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line":1,
"col":97
}
],
"type":"parsing_exception",
"reason":"[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line":1,
"col":97
},
"status":400
}
Any ideas so we can get this documented for posterity? Thanks!