Era Software

No results match your query

2. Write data

Estimated reading time: 3 minutes
  • tutorial
  • eracloud

Now that you have an account, you’re ready to manage and learn from your logs with EraSearch. In this guide, you'll write data to your database using the EraSearch REST API.

Before you begin
Copy
Copied!

Copy the service URI and API key for your EraCloud account. You can find that information on your account’s Overview page.

Writing data
Copy
Copied!

Use the EraSearch REST API to connect and write to your database. All writes go to the /_bulk endpoint and the API accepts JSON-formatted data. This page uses cURL to show how the API works, but you can use any language or framework to make HTTP requests to your database.

Write one document
Copy
Copied!

The example below writes one document

document

A document is a JSON object made up of data. In EraSearch, all documents have a unique identifier (_id) and a timestamp (_ts). Most documents include additional fields. Here's an example of a document:

Copy
Copied!
{"_id":4248176661010579457,"_line":"access","response":200,"_ts":1634060854000}
to the my_era_logs index

index

An index is a group of similar documents. With EraSearch, you can query documents in one or more indexes to optimize your searches.

. The document has one field

field

A field is data stored as a key and value pair.

with the key _line, and EraSearch creates the index for you if the index doesn't exist.

To write the document to your database, paste this command into your terminal, replacing YOUR_SERVICE_URI and YOUR_API_KEY with the information you copied earlier:

Copy
Copied!
$ curl -XPOST 'YOUR_SERVICE_URI/_bulk' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{"index":{"_index":"my_era_logs"}}
  {"_line": "my first log line"}'

Note: _line is a recognized field key in EraSearch. The database auto-parses _line values and stores them as distinct strings for future queries. For example, EraSearch stores the field value above as ["my","first","log","line"]. By default, EraSearch doesn't auto-parse the values of other field keys such as line or _logline.

EraSearch's response looks like the example below. The response shows information about the write, including:

  • errors - A boolean value set to false if all writes succeed.
  • _id - A unique, auto-generated numerical identifier for the document.
  • status - An HTTP status code for the write.
  • took - An integer showing the time EraSearch takes, in milliseconds, to complete all writes.
Copy
Copied!
{
   "errors" : false,
   "items" : [
      {
         "index" : {
            "_id" : "16051860674059239424",
            "_index" : "my_era_logs",
            "_shards" : {
               "failed" : 0,
               "successful" : 1,
               "total" : 1
            },
            "_type" : "_doc",
            "status" : 201
         }
      }
   ],
   "took" : 361
}

Write several documents
Copy
Copied!

The example below writes two more documents to the my_era_logs index. When writing several documents, you must specify the index between each document.

Copy
Copied!
$ curl -XPOST 'YOUR_SERVICE_URI/_bulk' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{"index":{"_index":"my_era_logs"}}
  {"_line": "time is an era"}
  {"index":{"_index":"my_era_logs"}}
  {"_line": "see the forest through the logs"}'

EraSearch's response is similar to the one shown above. For this example, the items array has two entries, one for each document.

Copy
Copied!
{
   "errors" : false,
   "items" : [
      {
         "index" : {
            "_id" : "13330711450665680896",
            "_index" : "my_era_logs",
            "_shards" : {
               "failed" : 0,
               "successful" : 1,
               "total" : 1
            },
            "_type" : "_doc",
            "status" : 201
         }
      },
      {
         "index" : {
            "_id" : "13330711450665680897",
            "_index" : "my_era_logs",
            "_shards" : {
               "failed" : 0,
               "successful" : 1,
               "total" : 1
            },
            "_type" : "_doc",
            "status" : 201
         }
      }
   ],
   "took" : 337
}

Tip: If you're ready for more data, visit the list of write integrations for all the ways to write real-time data to EraSearch.

Next steps
Copy
Copied!

You have your account, you have your data, and now, you're ready to query. Next, visit 3. Query data to explore data in EraSearch's UI.