• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

API Gateway for Elasticsearch with declarative querying and out-of-the-box access controls

ReactiveSearch API

Tests

Note: Development has moved to a private repository. This repository is used for release management.

ReactiveSearch API is a declarative, open-source API for querying Elasticsearch. It also acts as a reverse proxy and API gateway to an Elasticsearch cluster. ReactiveSearch API is best suited for site search, app search and e-commerce search use-cases.

Why use ReactiveSearch API

Lets take a search query for a books e-commerce site where a user is searching for the keyword "chronicles" on either title or author fields, has a rating filter applied to only return books with a rating gte 4.

This query takes ~80 lines of code to write with Elasticsearch's DSL. The same query can be expressed in ~20 lines of code with ReactiveSearch.

Lets understand the key differences between the two formats:

  1. The Elasticsearch query is imperative in nature, makes use of search-engine specific terminologies. This makes it more expressive at the cost of a higher learning curve. In comparison, the ReactiveSearch query is declarative and hides the implementation details.

  2. A ReactiveSearch query isn't prone to the nesting hell that Elasticsearch's query is. It expresses each query individually and then composes them together using the react property.

  3. ReactiveSearch query's declarative nature also makes it composable. It is easy to capture intent, enrich the query and apply access control checks to the individual queries.

  4. ReactiveSearch query's declarative nature also makes it a perfect fit for exposing it to publicly inspectable web and mobile networks. Exposing Elasticsearch's DSL in such a setting isn't recommended as it opens up a script injection attack vector.

Full API reference for ReactiveSearch is available over here.

Installation

Running it

In order to run reactivesearch-api, you'll require an Elasticsearch node. There are multiple ways you can setup an Elasticsearch, either locally or remotely. We, however, are delineating the steps for local setup of a single node Elasticsearch via it's Docker image.

Note: The steps described here assumes a docker installation on the system.

  1. Create a docker network
docker network create reactivesearch
  1. Start a single node Elasticsearch cluster locally
docker run -d --rm --name elasticsearch -p 9200:9200 -p 9300:9300 --net=reactivesearch -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.2.0

NOTE: It is advised to use -e "xpack.security.enabled=false" for local runs of ElasticSearch since otherwise ES is not available on :9200.

OR

Alternative to using Elasticsearch, you can also start a single node OpenSearch cluster locally

docker run --name opensearch --rm -d -p 9200:9200 -e http.port=9200 -e discovery.type=single-node -e http.max_content_length=10MB -e http.cors.enabled=true -e http.cors.allow-origin=\* -e http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -e http.cors.allow-credentials=true --net=reactivesearch opensearchproject/opensearch:1.3.2
  1. Start Zinc locally
mkdir data
docker run -v /full/path/of/data:/data -e ZINC_DATA_PATH="/data" -p 4080:4080 \
    -e ZINC_FIRST_ADMIN_USER=appbase -e ZINC_FIRST_ADMIN_PASSWORD=zincf0rappbase \
    --name zinc public.ecr.aws/zinclabs/zinc:latest
  1. Start ReactiveSearch locally
docker build -t reactivesearch . && docker run --rm --name reactivesearch -p 8000:8000 --net=reactivesearch --env-file=config/docker.env reactivesearch

For convenience, the steps described above are combined into a single docker-compose file. You can execute the file with command:

docker-compose up

Building

To build from source you need Git and Go (version 1.11 or higher).

You can build the binary locally by executing the following command from the project directory:

make

This produces an executable & plugin libraries in the root project directory. To start the Reactivesearch server, run:

./build/reactivesearch --env=config/manual.env --log=info

Alternatively, you could execute the following commands to start the server without producing an executable, (but still produce the plugin libraries):

make plugins
go run main.go --env=config/manual.env

Note: Running the executable assumes an active Elasticsearch upstream whose URL is provided in the .env file.

Logging

Define the run time flag (log) to change the default log mode, the possible options are:

debug

Most verbose, use this to get logs for elasticsearch interactions.

info

Prints the basic information

error (default)

Only log the errors

profiling

Set the profiling flag to true at runtime to enable net profiling endpoints. Profiling endpoints are exposed at /debug/pprof route.

Profiling CPU (time taken):

An example of profiling for CPU usage is: /debug/pprof/profile (will wait for 30s and return a profile), or You can directly hit go tool pprof -http=":8080" http://localhost:8000/debug/pprof/profile to get a profile UI (top, graph, flamegraph) for time taken.

Profiling Heap:

An example for profiling for heap usage is: /debug/pprof/heap (will return a profile for the point in time), or You can directly hit go tool pprof -http=":8080" http://localhost:8000/debug/pprof/heap to get a profile UI (top, graph, flamegraph) of heap usage.

diff-logs

Set the diff-logs flag to false (defaults to true) at runtime to disable the use of log diffing algorithm. For high-throughput use-cases (100 requests/sec or above), the log diffing algorithm consumes signficant CPU usage (about ~2 CPU cores per 100 requests/sec) that can be saved by turning off log diffing.

TLS Support

You can optionally start Reactivesearch to serve https requests instead of http requests using the flag https. You also need to provide the server key & certificate file location through the environment file. config/manual.env is configured to use demo server key & certificates, which works for localhost.

    go run main.go --log=info --env=config/manual.env --https

If you wish to manually test TLS support at localhost, curl needs to be also passed an extra parameter providing the cacert, in this case.

    curl https://foo:bar@localhost:8000/_user --cacert sample/rootCA.pem

JWT Key Loading through HTTP

If you wish to test loading JWT Key through HTTP, you can use the following commands to start a HTTP server serving the key

    cd sample
    python -m SimpleHTTPServer 8500

Then start ReactiveSearch using the command:

    go run main.go --log=info --env=config/manual-http-jwt.env

ReactiveSearch also exposes an API endpoint to set the key at runtime, so this need not be set initially.

Run Tests

Currently, tests are implemented for auth, permissions, users and billing modules. You can run tests using:

make test

or

go test -p 1 ./...

Extending ReactiveSearch API

The functionality in ReactiveSearch can extended via plugins. A ReactiveSearch plugin can be considered as a service in itself; it can have its own set of routes that it handles (keeping in mind it doesn't overlap with existing routes of other plugins), define its own chain of middlewares and more importantly its own database it intends to interact with (in our case it is Elasticsearch). For example, one can easily have multiple plugins providing specific services that interact with more than one database. The plugin is responsible for its own request lifecycle in this case.

However, it is not necessary for a plugin to define a set of routes for a service. A plugin can easily be a middleware that can be used by other plugins with no new defined routes whatsoever. A middleware can either interact with a database or not is an implementation choice, but the important point here is that a plugin can be used by other plugins as long as it doesn't end up being a cyclic dependency.

Each plugin is structured in a particular way for brevity. Refer to the plugin docs which describes a basic plugin implementation.

Models

Since every request made to Elasticsearch hits ReactiveSearch server first, it becomes beneficial to provide a set of models that allow a client to define access control policies over the Elasticsearch RESTful API and ReactiveSearch's functionality. ReactiveSearch provides several essential abstractions as plugins that are required in order to interact with Elasticsearch and ReactiveSearch itself.

Available Plugins

User

In order to interact with ReactiveSearch, the client must define either a User or a permission. A User encapsulates its own set of properties that defines its capabilities.

  • username: uniquely identifies the user
  • password: verifies the identity of the user
  • is_admin: distinguishes an admin user
  • categories: analogous to the Elasticsearch's API categories, like Cat API, Search API, Docs API and so on
  • acls: adds another layer of granularity within each Elasticsearch API category
  • ops: operations a user can perform
  • indices: name/pattern of indices the user has access to
  • email: user's email address
  • created_at: time at which the user was created

Permission

A User can create a Permission resource and associate it with a User, defining its capabilities in order to access Elasticsearch's RESTful API. Permissions serve as an entry point for accessing the Elasticsearch API and has a fixed time-to-live unlike a user, after which it will no longer be operational. A User is always in charge of the Permission they create.

  • username: an auto generated username for Basic Auth access
  • password: an auto generated password for Basic Auth access
  • owner: represents the owner of the permission
  • creator: represents the creator of the permission
  • categories: analogous to the Elasticsearch's API categories, like Cat API, Search API, Docs API and so on
  • acls: adds another layer of granularity within each Elasticsearch API category
  • ops: operations a permission can perform
  • indices: name/pattern of indices the permission has access to
  • sources: source IPs from which a permission is allowed to make requests
  • referers: referers from which a permission is allowed to make requests
  • created_at: time at which the permission was created
  • ttl: time-to-live represents the duration till which a permission remains valid
  • limits: request limits per categories given to the permission
  • description: describes the use-case of the permission

Category

Categories can be used to control access to data and APIs in ReactiveSearch. Along with Elasticsearch APIs, categories cover the APIs provided by ReactiveSearch itself to allow fine-grained control over the API consumption. For Elasticsearch, Categories broadly resembles to the API classification that Elasticsearch provides such as Document APIs, Search APIs, Indices APIs and so on. For ReactiveSearch, Categories resembles to the additional APIs on top of Elasticsearch APIs, such as analytics and book keeping. Refer to category docs for the list of categories that ReactiveSearch supports.

ACL

ACLs allow a fine grained control over the Elasticsearch APIs in addition to the Categories. Each ACL resembles an action performed by an Elasticsearch API. For brevity, setting and organising Categories automatically sets the default ACLs associated with the set Categories. Setting ACLs adds just another level of control to provide access to Elasticsearch APIs within a given Category. Refer to acl docs for the list of acls that ReactiveSearch supports.

Op

Operation delineates the kind of operation a request intends to make. The operation of the request is identified before the request is served. The classification of the request operation depends on the use-case and the implementation of the plugin. Operation is currently classified into three kinds:

  • Read: operation permits read requests exclusively.
  • Write: operation permits write requests exclusively.
  • Delete: operation permits delete requests exclusively.

In order to allow a user or permission to make requests that involve modifying the data, a combination of the above operations would be required. For example: ["read", "write"] operation would allow a user or permission to perform both read and write requests but would forbid making delete requests.

Request Logging

ReactiveSearch server currently maintains audit logs for all the requests made via it to elasticsearch. Both request and responses are stored for the users to view and inspect later. The request logs can be fetched for both specific indices or the whole cluster. The dedicated endpoints to fetch the index/cluster logs can be found here.

ReactiveSearch: UI Libraries

The ReactiveSearch API is used by ReactiveSearch and Searchbox libraries. If you're building a search UI using React, Vue, Flutter, React Native or Vanilla JS, these libraries provide scaffolding and commonly used search components that can compress weeks of development time into days.

ReactiveSearch 🍞 and appbase.io 🧈

appbase.io extends the opensource ReactiveSearch API with the following functionalities:

  1. Actionable Analytics capture telemetry from the ReactiveSearch API and provide powerful search-driven insights into users, clicks, conversions, geographical distribution, slow searches and more.
  2. Search Relevance provides a REST API and point-and-click interface to deploy a search relevance strategy by being able to configure language, Search/Aggregation/Results settings, Query Rules.
  3. Application Cache provides a blazing fast search performance and improved thorughput for search.
  4. UI Builder allows creating Search and Recommendations UI widgets with no code.

You can deploy appbase.io in cloud. We also provide one-click installs for AWS, Heroku, Docker and Kubernetes. Get started with these over here.

Docs

Refer to the REST API docs for ReactiveSearch.

More Repositories

1

dejavu

A Web UI for Elasticsearch and OpenSearch: Import, browse and edit data with rich filters and query views, create reference search UIs.
JavaScript
8,366
star
2

reactivesearch

Search UI components for React and Vue
JavaScript
4,899
star
3

mirage

🎨 GUI for simplifying Elasticsearch Query DSL
TypeScript
2,202
star
4

reactivemaps

A data aware UI components library for building realtime maps
JavaScript
941
star
5

gem

💎 GUI for Data Modeling with Elasticsearch
JavaScript
662
star
6

Docbase

Turn .md docs into beautiful sites
JavaScript
592
star
7

abc

Power of appbase.io via CLI, with nifty imports from your favorite data sources
Go
472
star
8

searchbox

Lightweight and performance oriented search box UI component libraries for React, Vue, React Native, JS and Flutter
JavaScript
182
star
9

playground

A storybook playground for ReactiveMaps and ReactiveSearch
JavaScript
47
star
10

appbase-js

appbase.io search client library for JavaScript
JavaScript
41
star
11

Docs

ReactiveSearch Developer Hub
JavaScript
33
star
12

reactivecore

Core architecture of reactive UI libraries
JavaScript
33
star
13

dashboard

ReactiveSearch cloud dashboard
JavaScript
32
star
14

appbase-droid

Elasticsearch and appbase.io library for Android (and Java)
Java
24
star
15

appbase-swift

Swift Library for appbase.io and ElasticSearch
Swift
24
star
16

reactivebase

Data components for building reactive UIs
JavaScript
18
star
17

twitterclone

twitter clone built with appbase.io and AngularJS
JavaScript
16
star
18

designkit

Design kit for appbaseio ecosystem
JavaScript
14
star
19

esc

ESC: ElasticSearch Cookbook, with example recipes 📘
JavaScript
13
star
20

meetupblast

Find out what great meetups people are going to!
JavaScript
12
star
21

reactive-manual

Docs for ReactiveSearch (and Maps)
JavaScript
12
star
22

vue-reactivesearch

This project has been moved to https://github.com/appbaseio/reactivesearch/
JavaScript
11
star
23

reactivesearch-api-docker

HTML
9
star
24

heartbeat-frontend

Heartbeat: Transform REST API endpoints to streaming APIs
JavaScript
7
star
25

vue-playground

A storybook playground for Vue ReactiveSearch
Vue
7
star
26

batteries

Pluggable modules for mappings, search preview and analytics
JavaScript
7
star
27

go-appbase

An ElasticSearch + appbase.io client library (includes data streaming support) for Go
Go
6
star
28

reactivebase-native

Native data components for building reactive UIs
JavaScript
6
star
29

flutter-searchbox

SearchBox UI component library for flutter
Dart
6
star
30

appbase-redis

A realtime events-based document store
JavaScript
5
star
31

reactivesearch-realm-function

Crate for ReactiveSearch API which creates a Realm function based API gateway
TypeScript
5
star
32

docbase-manual

Manual for docbase
HTML
5
star
33

vue-searchbox

JavaScript
4
star
34

generator-docbase

Docbase generator
JavaScript
4
star
35

react-searchbox

JavaScript
3
star
36

reactive-maps-onboarding

JavaScript
3
star
37

searchbox-js

JavaScript
3
star
38

streaming-transporter

Shell
3
star
39

analytics.js

Universal analytics library for appbase.io / ElasticSearch
JavaScript
3
star
40

pipelines-action

GitHub Action to let users create pipelines from a repository directly
JavaScript
3
star
41

grunt-docbase

Grunt plugin to generate html files from your docbase project.
JavaScript
2
star
42

EScompanion

A companion installation app for Autopilot
Go
2
star
43

statuspage

HTML
2
star
44

android-searchbox

Android Search UI widget to build customizable mobile search layouts
Java
2
star
45

appbase.js-deprecate

JavaScript Wrapper for Appbase Rest API
JavaScript
2
star
46

statusp

Python
1
star
47

reactivesearch-shopify-plugin

Shopify Plugin for ReactiveSearch
JavaScript
1
star
48

faceted-search-template

JavaScript
1
star
49

oasis

Oasis
JavaScript
1
star
50

mitter

JavaScript
1
star
51

serverless-search

Dockerfile
1
star
52

appbase-hackathon-deprecate

1
star
53

geo-search-template

JavaScript
1
star
54

flutter-searchbox-typeahead-example

Dart
1
star
55

clients

An experiment in auto-generated REST clients.
1
star
56

pipelines-template

Template repo to get started with ReactiveSearch Pipelines Action
JavaScript
1
star
57

customization-with-reactivesearch

JavaScript
1
star
58

appbaseio-heroku

Dockerfile
1
star
59

reactivesearch-api-k8s

1
star
60

searchbook

Search onboarding
JavaScript
1
star