opendistro-for-elasticsearch / sql

🔍 Open Distro SQL Plugin
https://opendistro.github.io/for-elasticsearch/features/SQL%20Support.html
Apache License 2.0
620 stars 186 forks source link

When using * in select, myIndex.field.subFieldA > myIndex.field.subFieldB fails #1055

Open FreCap opened 3 years ago

FreCap commented 3 years ago

Thank @penghuo for the #795 fix!

a follow up on this.

When using * in a subfield (non-nested), breaks


POST my_test_ndex/_doc/
{
  "field1": {
    "subFieldA": 1,
    "subFieldB": 2
  },
  "field2": {
    "subFieldA": 1,
    "subFieldB": 2
  }
}

// Exception
POST _opendistro/_sql
{
  "query": """SELECT field2.* FROM
  my_test_ndex as i 
  WHERE 
  i.field1.subFieldA <i.field1.subFieldB
    LIMIT 50;"""
}

---->>

{
  "error": {
    "reason": "Error occurred in Elasticsearch engine: all shards failed",
    "details": """Shard[0]: ScriptException[runtime error]; nested: IllegalArgumentException[No field found for [subFieldA] in mapping with types []];

For more details, please send request for Json format to see the raw response from elasticsearch engine.""",
    "type": "SearchPhaseExecutionException"
  },
  "status": 400
}
// Exception
POST _opendistro/_sql
{
  "query": """SELECT field1.* FROM
  my_test_ndex as i 
  WHERE 
  i.field1.subFieldA <i.field1.subFieldB
    LIMIT 50;"""
}

------->>
{
  "error": {
    "reason": "Error occurred in Elasticsearch engine: all shards failed",
    "details": """Shard[0]: ScriptException[runtime error]; nested: IllegalArgumentException[No field found for [subFieldA] in mapping with types []];

For more details, please send request for Json format to see the raw response from elasticsearch engine.""",
    "type": "SearchPhaseExecutionException"
  },
  "status": 400
}

These instead work:

POST _opendistro/_sql
{
  "query": """SELECT * FROM
  my_test_ndex as i 
  WHERE 
  i.field1.subFieldA <i.field1.subFieldB
    LIMIT 50;"""
}
POST _opendistro/_sql
{
  "query": """SELECT field1 FROM
  my_test_ndex as i 
  WHERE 
  i.field1.subFieldA <i.field1.subFieldB
    LIMIT 50;"""
}
POST _opendistro/_sql
{
  "query": """SELECT field2 FROM
  my_test_ndex as i 
  WHERE 
  i.field1.subFieldA <i.field1.subFieldB
    LIMIT 50;"""
}
penghuo commented 3 years ago

Thanks for reporting the issue. Checking now.