---
# System prepended metadata

title: Untitled

---

> []# Build App Search With ReactiveSearch and OpenSearch

## TOC

1. What is ReactiveSearch / Key Benefits
    @Siddharth to write this [0]


**2. OpenSearch and History**

You may have already known the update from Elastic that they have decided not to release new versions under the open-source license since January 2021. New releases, instead, will be provided under Elastic License or the Server Side Public License. The [change](https://www.elastic.co/pricing/faq/licensing) included the Apache 2.0 license for Elasticsearch and Kibana to be both licensed under the Elastic License and SSPL 1.0.

After the Elastic's decision, OpenSearch was born. The project is an effort from Amazon and contributors to maintain the ALv2 licensed. [OpenSearch](https://opensearch.org/faq/) 1.0 picks up from where ElasticSearch v7.10.2 left off.

**2.1. OpenSearch and OpenSearch Dashboard**

So OpenSearch was born to ensure the continuum of an open-source license for Elasticsearch and Kibana. OpenSource is a search and analytics stack that allows you to perform various tasks such as real-time app monitoring, log analytics, and website search. It provides a scalable solution for accessing large volumes of data with an integrated visualization tool that is OpenSearch Dashboard.

Similar to Elasticsearch and Apache Solr, OpenSearch is based upon the Apache Lucene search library. OpenSearch and OpenSearch Dashboards originated from Elasticsearch 7.10.2 and Kibana 7.10.2 and as of July 2021, OpenSearch version 1.0 was released. The search suite can be installed via Docker or tar file. Let’s find out how we can set up OpenSearch locally.

**3. Setting up OpenSearch locally**

The best way of learning a new software is by actually trying it. Thanks to the continuous distribution under open-source, we can install in our local computer without any price string attached. The easiest way to install is to use the Docker image. Having said that, the prerequisite to the instructions is Docker. If you haven’t had it, check Docker's official [website](https://www.docker.com/) and install it. 

OpenSearch Docker images use amazonlinux:2 as the base image. To run Docker locally, you should use 4GM memory at a minimum. Go to Preferences > Resources to change the settings.

Once done, in your terminal, execute the command below.

```bash=
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=opensearch opensearchproject/opensearch:latest
```

Note that there are more options in the command. Among them, discovery.type=single-node was added to avoid production bootstrap checks.

When you set up Elasticsearch or, actually, any other open-source software, it is common that users face unexpected issues derived from misconfigurations and incompatibility with their local environment. Elasticsearch used to display the issues as warnings that can be missed by people. To ensure that these settings receive attention, Elasticsearch puts bootstrap checks for startup, thus OpenSearch does that too.

Since we run this in our local environment with a single node, without the single node option, it will complain. To suppress it, we need to pass that option.

Back to local setup. There were more added variables in the docker command as below:

```bash=
http.cors.enabled=true
http.cors.allow-origin=* # you can also whitelist a specific domain instead of allowing all origins
http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization # allows additional headers
http.cors.allow-credentials=true
http.max_content_length=10MB
```

All these were to allow cross-origin requests from our browser app built using ReactiveSearch. There are numerous network setting parameters. To find out more options, check the Elasticsearch [network reference](https://www.elastic.co/guide/en/elasticsearch/reference/7.13/modules-network.html#http-settings).

The docker command will download the OpenSearch image and start running it. Let’s test if your OpenSearch is running normally. Open a new terminal and try:

```bash=
curl -XGET https://localhost:9200 -u admin:admin --insecure
```
This will give you the JSON response like:
```json=

{
     "name" : "9e2732ce355c",
     "cluster_name" : "docker-cluster",
     "cluster_uuid" : "RoLlFtjqTVyNnkTqbMFgqw",
     "version" : {
          "distribution" : "opensearch",
          "number" : "1.0.0",
          "build_type" : "tar",
          "build_hash" : "34550c5b17124ddc59458ef774f6b43a086522e3",
          "build_date" : "2021-07-02T23:22:21.383695Z",
          "build_snapshot" : false,
          "lucene_version" : "8.8.2",
          "minimum_wire_compatibility_version" : "6.8.0",
          "minimum_index_compatibility_version" : "6.0.0-beta1"
     },
     "tagline" : "The OpenSearch Project: https://opensearch.org/"
}
```

Let’s try the next command to retrieve specifications of your node.
```bash=
curl -XGET https://localhost:9200/_cat/nodes?v -u admin:admin --insecure
```
This will give your the specs detail on your node as below.
```bash=
ip     heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.17.0.2      20     97 10  0.19  0.47   0.32 dimr   *   9c53483a4c02
```
Finally, let’s check the list of plugins in your OpenSearch by:
```bash=
curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure
```
This will return all the components in your node.
```bash=
name     	component                   	version
9c53483a4c02 opensearch-alerting         	1.0.0.0
9c53483a4c02 opensearch-anomaly-detection	1.0.0.0
9c53483a4c02 opensearch-asynchronous-search   1.0.0.0
9c53483a4c02 opensearch-index-management 	1.0.0.0
9c53483a4c02 opensearch-job-scheduler    	1.0.0.0
9c53483a4c02 opensearch-knn              	1.0.0.0
9c53483a4c02 opensearch-notebooks        	1.0.0.0
9c53483a4c02 opensearch-performance-analyzer  1.0.0.0
9c53483a4c02 opensearch-reports-scheduler	1.0.0.0
9c53483a4c02 opensearch-security         	1.0.0.0
9c53483a4c02 opensearch-sql              	1.0.0.0
```
Since we confirmed that it is running normally in your local, if you want to stop the container, first check the container ID by:
```bash=
docker ps
```
Then, check the CONTAINER ID column for the ID value. In this case, it is 9c53483a4c02.
```bash=
CONTAINER ID   IMAGE                             	COMMAND              	CREATED     	STATUS     	PORTS                                                                                                  	NAMES
9c53483a4c02   opensearchproject/opensearch:latest   "./opensearch-docker..."   8 minutes ago   Up 8 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 9300/tcp, 0.0.0.0:9600->9600/tcp, :::9600->9600/tcp, 9650/tcp   sad_shamir
```
Run the docker stop command with the id.
```bash=
docker stop 9c53483a4c02
```
This will return the same ID in your command, which indicates it was successfully stopped.



**4. Setup ReactiveSearch API server to run along with OpenSearch**

Now that we’ve successfully configured OpenSearch, let’s try to run ReactiveSearch API along with OpenSearch.
First, create a new config file named config.env with the following contents:
```
ES_CLUSTER_URL=http://opensearch:9200
USERNAME=foo
PASSWORD=bar
```

Put your username and password instead of foo and bar and then save the file. In the same folder, run:

```bash=
docker run --rm --name reactivesearch -p 8000:8000 --net=opensearch --env-file=config.env appbaseio/reactivesearch-api
```

Note that the command pointed to the config file we just created. To test if it’s running normally, run:

```bash=
curl localhost:8000 -u foo:bar
```

This will give you a response that looks like:
```json=
{
  "name" : "cd34cadba56f",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "hrHHeJzwTP-X3zc49ZRt5w",
  "version" : {
    "number" : "7.10.2",
    "build_flavor" : "oss",
    "build_type" : "docker",
    "build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
```

**5. Building App Search with ReactiveSearch + OpenSearch**

We now would like to build a sample application using ReactiveSearch and OpenSearch. Since building a test app requires UI work, the best way to quick-start is to start with one of the reactive search templates from [CodeSandBox](https://codesandbox.io/s/reactivesearch-course-code-ih2jh). In the code package, check App.js. This javascript file contains the configurations to connect to ReactiveSearch.

You can see that there is a json config that looks like:
```javascript=
...
<ReactiveBase
      app="..."
      url="..."
>
```
These settings are to use ReactiveSearch and ElasticSearch hosted by appbaseio. Your localhost URL won’t be accessible from CodeSandBox unless you have already configured otherwise. If you are familiar with a cloud server service like AWS EC2, you can try the steps above to gain a publicly accessible URL.

In addition to the two variables, you will also need to add credentials that refer to your username and password you defined above.
```javascript=
...
<ReactiveBase
      app="..."
      url="..."
      credentials="foo:bar"
>
```
The credentials are the combination of the username and password delimited by colon.

If you want to try this in your local environment, you can try to clone [ReactiveSearch Starter App](https://github.com/appbaseio-apps/reactivesearch-starter-app) into your local computer and modify the App.js file.
```javascript=
...
<ReactiveBase
      app="YOUR_APP_NAME"
      url="localhost:8000"
      credentials="foo:bar"
>
```
Among the parameters, put the url you generated by the steps above, localhost:8000, in the url section. If you have created an app, you can use your app name.

6. Do more with appbase.io
    @Siddharth to write this
    
    // Rationale
    This is explaining what else can be done that is available in the commercial version of appbase.io.



## References:

[0] https://medium.appbase.io/reactive-search-3-0-ui-components-for-building-search-uis-51b926fc0d8b

[1] https://aws.amazon.com/blogs/opensource/stepping-up-for-a-truly-open-source-elasticsearch/

[2] https://opensearch.org/downloads.html

[3] https://docs.appbase.io/docs/reactivesearch/v3/overview/quickstart/