[SOLVED] Mistake input with Elastic PHP 8.5.0

I'm using PHP Client API for work with SQL (intensive)

But I've a problem.

In my first few unit tests, I was using a simple named index.

My surprise has been when trying to do the integration tests, when I took it out I already use aliases, like testing-analyzers

A query like this throws an exception

SELECT vac1_v,vac2_v,vac_v FROM test-analyzers WHERE id = 1 AND (vac1_v > 260 OR vac2_v > 260 OR vac3_v > 260)

$sql = ‘SELECT vac1_v,vac2_v,vac_v FROM test-analyzers WHERE id = 1 AND (vac1_v > 260 OR vac2_v > 260 OR vac3_v > 260)’

// Also try escaping the script -
// $sql = ‘SELECT vac1_v,vac2_v,vac_v FROM test\-analyzers WHERE id = 1 AND (vac1_v > 260 OR vac2_v > 260 OR vac3_v > 260)’

 $params = [
            'body' => [
                "query" => $sql
            ]
        ];

//params: [▼
// "body" => array:1 [▼
// "query" => "SELECT vac1_v,vac2_v,vac_v FROM test\-analyzers WHERE id = 1 AND //(vac1_v > 260 OR vac2_v > 260 OR vac3_v > 260)"
// ]

   $response = $client->sql()->query($params);

Mistake

400 Bad Request: {"error":{"root_cause":[{"type":"parsing_exception","reason":"line 1:37: mismatched input '\' expecting {,

"type":"parsing_exception","reason":"line 1:37: mismatched input '-' expecting {,

Any ideas?

I get a solution.

I need escape name of the index or alias with a hyphen - between escaped "": Example below

"query" => "SELECT log_id,vac1_v,vac2_v,vac3_v FROM "test-analyzers" WHERE log_id = 1 AND (vac1_v > 260 OR vac2_v > 260 OR vac3_v > 260)"

After this working fine.

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