Skip to content

2. Write data

Estimated time to read: 3 minutes

Acquisition notice

In October 2022, ServiceNow acquired Era Software. The documentation on this site is no longer maintained and is intended for existing Era Software users only.

To get the latest information about ServiceNow's observability solutions, visit their website and documentation.

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 the service URI and API key for your EraCloud account. You can find that information on your account’s Overview page.

Writing data

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

The example below writes one document to the my_era_logs index. The document has one field 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:

$ 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.
{
   "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

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.

$ 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.

{
   "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 write-integrations reference for all the ways to write real-time data to EraSearch.

Next steps

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.


Last update: August 7, 2023