However, issuing a syntactically very similar SQL query does return a result.
POST _xpack/sql?format=txt
{
"query": "select groupName from my_index where user.first = 'Alice' and user.last = 'Smith'"
}
This happens because the above is /translated to a query with outer type bool rather than nested. I'm having a hard time convincing myself that ES is doing the right thing here, and I'd argue that the intent of the above is mistranslated, and that the query above should try to find a nested doc matching both predicates.
This is an interesting scenario, but I don't know if we can do any better in this case. Having a bool with two nested statements in it (like it is behaving now), or a root nested query that has a bool in it with two term statements, how could these be differentiated at SQL query level?
No matter how you do it, the WHERE part has to have the form user.first='Alice' AND user.last='Smith'.
@paulcarey would you mind creating an issue in github for an enhancement regarding nested queries?
This probably won't be on our top priority list, but it gives us an idea for future improvements that might be considered.
Sorry for the delay @paulcarey. I looked at these issues and the first one (with different projection the document disappears from the results) it's indeed a bug. The idea is that both nested queries that get created are for the same path and both use inner_hits. If one of the inner_hits doesn't return anything, the overall result is nothing, because they clash. It's a bit more complicated, but I hope now it's just a bit more clear.
The idea is to name each inner_hits statement so that the result can differentiate between them. And at the moment, ES-SQL doesn't do this.
Regarding 33079, I was wondering if JsonPath or some variant of it had been considered as a way to define complex queries? For example, the Alice White query I mentioned above could be satisfied with:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.