Skip to content

Commit fff5381

Browse files
committed
another example esql article
1 parent 90b20ff commit fff5381

File tree

1 file changed

+22
-9
lines changed
  • examples/esql-article/src/main/java/co/elastic/clients/esql/article

1 file changed

+22
-9
lines changed

examples/esql-article/src/main/java/co/elastic/clients/esql/article/EsqlArticle.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,35 @@ public static void main(String[] args) throws IOException, SQLException {
143143

144144
System.out.println("Finished in: " + Duration.between(start, end).toMillis() + "\n");
145145

146-
String query =
146+
String queryAuthor =
147147
"""
148-
from books
149-
| where author == "Isaac Asimov"
150-
| sort year desc
148+
from books
149+
| where author == "Isaac Asimov"
150+
| sort year desc
151151
| limit 10
152-
""";
153-
List<Book> queryRes = (List<Book>) client.esql().query(ObjectsEsqlAdapter.of(Book.class), query);
152+
""";
154153

155-
System.out.println("~~~\nObject result:\n" + queryRes.stream().map(Book::title).collect(Collectors.joining("\n")));
154+
List<Book> queryRes = (List<Book>) client.esql().query(ObjectsEsqlAdapter.of(Book.class), queryAuthor);
156155

157-
ResultSet resultSet = client.esql().query(ResultSetEsqlAdapter.INSTANCE, query);
156+
System.out.println("~~~\nObject result author:\n" + queryRes.stream().map(Book::title).collect(Collectors.joining("\n")));
158157

159-
System.out.println("~~~\nResultSet result:");
158+
ResultSet resultSet = client.esql().query(ResultSetEsqlAdapter.INSTANCE, queryAuthor);
159+
160+
System.out.println("~~~\nResultSet result author:");
160161
while (resultSet.next()) {
161162
System.out.println(resultSet.getString("title"));
162163
}
164+
165+
String queryPublisher =
166+
"""
167+
from books
168+
| where publisher == "Penguin"
169+
| sort ratings desc
170+
| limit 10
171+
| sort title asc
172+
""";
173+
174+
queryRes = (List<Book>) client.esql().query(ObjectsEsqlAdapter.of(Book.class), queryPublisher);
175+
System.out.println("~~~\nObject result publisher:\n" + queryRes.stream().map(Book::title).collect(Collectors.joining("\n")));
163176
}
164177
}

0 commit comments

Comments
 (0)