Interactive Examples using the ReactiveSearch REST API
While appbase.io maintains 100% API compatibility with Elasticsearch, it also provides a declarative API to query Elasticsearch. This is the recommended way to query via web and mobile apps as it prevents query injection attacks. It composes well with Elasticsearch's query DSL, and lets you make use of appbase.io features like caching, query rules, server-side search settings, and analytics.
You can read the API reference for the ReactiveSearch API over here. In the following section, we will show interactive examples for using the API.
In the basic usage example, we will see how to apply a search query using the ReactiveSearch API.
In this example, we will see how to apply a search and a facet query together. This makes use of two queries.
We also introduce a concept for executing a query that depends on another query using the
execute properties. Here, the search query also utilizes the value of the facet query while returning the documents.
In this example, we will be using three queries: search + facet + result. If you had a UI, visualize a scenario where the user has entered something in the searchbox and selected a value in the facet filter. These two should inform the final results that get displayed.
executeproperty's usage shows whether we expect the particular query to return a response. It's set to
trueonly for the results (books) query, as a result, only that key is returned back.
In this example, we will see a more complex use-case where an additional range filter is also applied.
In this example, we will see an application of a search query along with a geo query. We are searching for earthquakes within 100mi distance of a particular location co-ordinate.
In this example, we make two search queries - each on a different index.
In this example, we show how to only return distinct results back from a search query, the equivalent of a DISTINCT / GROUP BY clause in SQL.
In this example, we show how to use Elasticsearch's query DSL using the
defaultQuery property. This provides the flexibility of overriding the ReactiveSearch API completely for advanced use-cases.
In this example, we show how to use Elasticsearch's query DSL for writing a term query using the
customQuery property. This query is then applied to the search results query, which is composed using the ReactiveSearch API.
In this example, we see usage of advanced search settings that show how to record custom analytics events, enable query rules, and enable cache (per request).
In this example, we see usage of
AI Answer functionality to get answer to the search query based on the top hits.