Overview
In the following article, I investigated how to search nested fields using Strapi.
This time, I will investigate how to do the same thing with Drupal. For this investigation, Book and Author content has already been registered in the following article.
The following article was helpful for filtering methods.
https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/filtering
Search Examples
The following searches are performed against:
/jsonapi/node/book?
Search for books containing an author with hobby=dance
- SHORT
filter[field_authors.field_hobby]=dance
or
filter[field_authors.field_hobby][value]=dance
- NORMAL
filter[ex1][condition][path]=field_authors.field_hobby&filter[ex1][condition][value]=dance
Search for books containing an author whose hobby contains “dan”
- SHORT
filter[field_authors.field_hobby][operator]=CONTAINS&filter[field_authors.field_hobby][value]=dan
- NORMAL
filter[ex1][condition][path]=field_authors.field_hobby&filter[ex1][condition][operator]=CONTAINS&filter[ex1][condition][value]=dan
(Reference) Search for books containing an author whose hobby is play or sing
filter[ex1][condition][path]=field_authors.field_hobby&filter[ex1][condition][operator]=IN&filter[ex1][condition][value][1]=sing&filter[ex1][condition][value][2]=play
(Reference) Using the Search API
By using the following module, it appears possible to search across multiple content types, specify field names, add facets, and more.
https://www.drupal.org/project/jsonapi_search_api
The following article introduces how to use it, so please refer to it.
</en/posts/8d7aa7c33abffc/#search-api>
Creating an Index
For example, configure the Search API index as follows.

This allows you to also retrieve book information from the following URL.
/jsonapi/index/book
Compared to the standard jsonapi (/jsonapi/node/book, etc.), the meta field includes a count, which allows you to check the total number of search results. (There may be a way to add this to the standard jsonapi as well, but this is unknown due to insufficient investigation.)
Filtering
Also, for “searching books containing an author with hobby=dance,” since we assigned the property path field_authors:entity:field_hobby to the machine name field_hobby in the earlier index creation, it could be executed with the following simple query.
- SHORT
filter[field_hobby]=dance
- NORMAL
filter[ex1][condition][path]=field_hobby&filter[ex1][condition][value]=dance
Facets
Furthermore, (based on uncertain knowledge at the time of writing this article,) one of the major advantages of using the Search API is the ability to use facets.
Summary
There may be some inaccurate information, but we hope this serves as a useful reference for searching nested structures in Drupal and combining JSON:API with the Search API.