Is querying elasticsearch directly from NextJS server-side a bad pattern?

Hi everyone,

I’m building a Next.js app (App Router) and trying to decide on the right way to integrate Elasticsearch.

I know Next.js allows direct server-side data access without needing an API layer, which makes this approach convenient. However, I’ve also seen recommendations to place Elasticsearch behind a separate backend/API.

My main questions:

  • Is querying Elasticsearch directly from Next.js server-side considered a bad practice?

  • Are there concerns around security, scaling, or maintainability with this approach?

  • At what point does it make sense to introduce a dedicated API layer instead?

For context:

  • This is a production scale app

  • Queries include text heavy searches with some aggregations and ranking for sponsored results

Would appreciate any guidance or real-world experiences.

Thanks!