# Create Core & Add Data in Solr

Install solr first [introduction](https://abisec.gitbook.io/devsecops/miscellaneous/apache-solr/introduction "mention")

1. Now config solr setup:

```bash
sudo chmod -R u+w /var/solr/data
```

2. Create core data:&#x20;

```bash
sudo su - solr -c "/opt/solr/bin/solr create -c coder -n data_driven_schema_configs" 
```

3. To delete core data:&#x20;

```bash
/opt/solr/bin/solr delete -c coder
```

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2Fr6HqCF9u4MO1eZhj8cJn%2Fimage.png?alt=media&#x26;token=9f099cc1-00ee-4813-9ce0-c24288280c19" alt=""><figcaption></figcaption></figure>

Then,  create the solr core again:&#x20;

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2FCrMbSXR9tEF2jPiXi06l%2Fimage.png?alt=media&#x26;token=5ff816a4-c2e4-4deb-aacc-73ff2632dbdd" alt=""><figcaption></figcaption></figure>

In case, you got any error check on the logs: \\

```bash
cd /var/solr
```

Try to give 755 permission if you stuck for permission there.

For restart:&#x20;

```bash
sudo service solr restart
```

## POST request to the Solr server running on `127.0.0.1:8983` with the content type set to JSON

* Solr core name: coder

```bash
curl -X POST \
  -H 'Content-Type: application/json' \
  'http://127.0.0.1:8983/solr/coder/update/json/docs' \
  --data-binary '{
    "id": "02",
    "first_name": "Abishek",
    "last_name": "Kafle",
    "title": "DevOps and Security",
    "cybername": "anoint"
  }'

```

```bash
sudo service solr restart
```

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2F2I8GNlESd0EqTnioKzgN%2Fimage.png?alt=media&#x26;token=8aebd30b-34cb-47d8-951c-488da718ca82" alt=""><figcaption></figcaption></figure>
