Skip to content

Commit e5bf3a9

Browse files
MattSchurrenejeglinskyagoerler
authored
Java: Search in Maps (#2219)
Co-authored-by: René Jeglinsky <rene.jeglinsky@sap.com> Co-authored-by: Adrian Görler <adrian.goerler@sap.com>
1 parent 1425807 commit e5bf3a9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

java/working-with-cql/query-api.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,29 @@ Select.from("bookshop.Books")
667667
.search(term -> term.has("Allen").or(term.has("Heights")));
668668
```
669669

670+
#### Search in Sub-Elements of Map <Beta />
671+
672+
You can search for values in sub-elements of a [cds.Map](../cds-data#cds-map) element by adding a path to the sub-element in the search scope:
673+
674+
```cds
675+
entity Book : cuid {
676+
category : String;
677+
details : Map;
678+
}
679+
```
680+
681+
For example to search for books in the "Software development" category having "CAP Java" within the _summary_ sub-element of the _details_ map:
682+
```Java
683+
Select.from(BOOK)
684+
.search("CAP Java", List.of("details.summary"))
685+
.where(p -> p.category().eq("Software development"));
686+
```
687+
688+
::: warning
689+
Searching within map element content can be expensive on large datasets. Use additional filters on non-map elements to reduce the dataset size.
690+
691+
Including the entire map element in the search scope triggers a full-text search on its JSON representation, matching both sub-element names and values. This behavior can yield unexpected results.
692+
:::
670693

671694
#### Using `where` Clause {#where-clause}
672695

0 commit comments

Comments
 (0)