Hi everyone,
I'm developing a frontend UI for an application that uses Elasticsearch as its search engine. We're currently designing the API contracts with our backend team, and one of the key topics we're debating is where to build the Elasticsearch queries.
Our frontend includes advanced search filters that can become quite complex (e.g., boolean combinations, ranges, nested fields). One approach we’ve considered is to generate the full Elasticsearch Query DSL on the frontend and send it to the backend, which would then forward it directly to Elasticsearch.
However, we’re concerned about:
- Security: Could this expose sensitive fields or allow query manipulation?
- Coupling: Does embedding ES DSL in the frontend tightly couple it to backend internals and make it harder to refactor later?
- Validation: How do we ensure only allowed fields and query types are used?
- Flexibility: Would we lose the ability to optimize or evolve search behavior if logic lives entirely in the frontend?
The alternative is to send a simplified, domain-specific filter object from the frontend (e.g. search text, filters, sort options), and let the backend build and validate the actual ES query.
My questions:
- Is it ever a good practice to send full ES queries from the frontend?
- What are the recommended ways to expose flexible search UIs to users while maintaining security and backend control?
- Are there known patterns that help in this situation?
I’d appreciate any insight or experience you can share — especially if you’ve faced similar decisions in production systems.
Thanks!