Sql api error . status code 500

when use sql rest api

post _sql
{
  "query": """
  select  site_name,projectName,count(*)  from dev_base_info  where area_id is not null and dev_name="ss"  group by site_name,projectName
  """
}

this return : Request failed to get to the server (status code: 500)

i check the es logs , nothing found.

when i change the sql like this:

post _sql
{
  "query": """
  select  site_name,projectName,count(*)  from dev_base_info  where area_id is not null  group by site_name,projectName
  """
}

it's ok

is there any config error? the es version is 8.15.0

1 Like

Hello,

Could you please try below query and confirm

POST /_sql?format=txt
{
"query": "select site_name,projectName,count(*) from dev_base_info where area_id is not null and dev_name='ss' group by site_name,projectName"
}

Thanks

Welcome!

Could you share the elasticsearch logs please?

No Elasticsearch SQL, é recomendado usar aspas simples para strings em consultas. Alterar sua consulta para usar aspas simples pode resolver o problema:

POST _sql
{
"query": """
SELECT site_name, projectName, COUNT(*)
FROM dev_base_info
WHERE area_id IS NOT NULL AND dev_name = 'ss'
GROUP BY site_name, projectName
"""
}