With version 5.0.0, the match_all query is throwing parsing_exception: [match_all] query malformed, no start_object after query name. Executing a basic match_all query over REST API works as intended.
$params = [
"index" => "foo",
"type" => "bar",
"query" => [
"match_all" => [],
],
];
The issue seems to be that the match_all query has no parameters. If I set the boost parameter to 1.0 (the default behaviour), the query works.
$params = [
"index" => "foo",
"type" => "bar",
"query" => [
"match_all" => [
"boost" => 1.0,
],
],
];
Ah, yeah, this is likely caused by PHP's json encoder not knowing what to do in this ambiguous case (more info here). And ES 5.0 is much stricter about parsing it's input, so now the array doesn't suffice.
I'll need to think about if there's a way we can cleanly fix this inside the client, not sure. It's hard because the client doesn't do any body validation, and blindly replacing parts of the input could be dangerous. There may be a safe way to inspect and fix common problems like this though. Will ponder :)
For now, you can use one of: (object)[], new \stdClass(), new class{} (depending on PHP version, the stdClass one should be available everywhere though).
So like this:
$params = [
"index" => "foo",
"type" => "bar",
"query" => [
"match_all" => (object)[],
],
];
Wouldn't this be enough ?
diff --git a/src/Elasticsearch/Serializers/SmartSerializer.php b/src/Elasticsearch/Serializers/SmartSerializer.php
index e35e409..d83d4ee 100644
--- a/src/Elasticsearch/Serializers/SmartSerializer.php
+++ b/src/Elasticsearch/Serializers/SmartSerializer.php
@@ -27,7 +27,7 @@ class SmartSerializer implements SerializerInterface
if (is_string($data) === true) {
return $data;
} else {
- $data = json_encode($data);
+ $data = json_encode($data, JSON_FORCE_OBJECT);
if ($data === '[]') {
return '{}';
} else {
@MichaelMure Unfortunately, that breaks things as well. See comments in: https://github.com/elastic/elasticsearch-php/pull/502
Basically, just as many things in the ES API rely on empty arrays as empty objects, so there's not a clear "best choice" in this case.
@polyfractal new \stdClass() works great.
Gonna close this, since I don't think there's really anything that we can do. At least not until (or if) the clients ever start doing body validation.
Most helpful comment
Ah, yeah, this is likely caused by PHP's json encoder not knowing what to do in this ambiguous case (more info here). And ES 5.0 is much stricter about parsing it's input, so now the array doesn't suffice.
I'll need to think about if there's a way we can cleanly fix this inside the client, not sure. It's hard because the client doesn't do any body validation, and blindly replacing parts of the input could be dangerous. There may be a safe way to inspect and fix common problems like this though. Will ponder :)
For now, you can use one of:
(object)[],new \stdClass(),new class{}(depending on PHP version, the stdClass one should be available everywhere though).So like this: