This code example generates 1000 example credit card transactions which include an anomaly that can be detected using Elastic’s anomaly detection tools.
-
Node.js
Node.js is required to run this code example. See the instructions to download and install Node.js at https://nodejs.org/en/download
-
Elastic deployment
Visit cloud.elastic.co to create a new deployment or use an existing deployment. Using an Elastic Serverless observability project is recommended for a simple start.
-
Clone this repository
Using a terminal, run the following command:
git clone https://github.com/elastic/observability-examples
-
Change directory to the code example folder:
cd observability-examples/anomaly-detection -
Install the code example’s dependencies:
npm install -
Run the code example to generate a JSON file named
transactions.ndjsoncontaining 1000 example transactions:node generate-transactions.js
Complete the following steps to upload the generated transactions.ndjson file to an Elastic deployment which will create a new index.
- Within the Elastic Observability solution, select Add data from the left-navigation menu.
- Select Application within the What do you want to monitor section.
- In the Search through other ways of ingesting data: input field, enter the text
Upload. - You should see the Upload a file tile appear. Select it.
- On the Upload data from a file page, click the Select or drag and drop a file link.
- In the file management window that appears, browse to and select the
transactions.ndjsonfile that was created when you ran thegenerate-transactions.jscode example. - You’ll then see a summary of the file contents that is to be imported. Click the Import button.
- Enter a Name for the index that will be created and click the Import button.
In your Elastic deployment create an Anomaly Detection Job using the index you created in the previous step.
- Within the Elastic Observability solution, select Machine Learning > Anomaly Detection > Jobs from the left-navigation menu.
- On the Select data view page, select the index you created in the previous step.
- You’ll be prompted to select a job creation wizard. Select Population.
- Within the Create job: Population wizard:
- Select Use full data and click the Next button.
- For the Population field, select IPAddress from the drop down menu.
- For the Add metric field, select Count(Event rate)
- You should see an initial graph of the data to be analyzed. Click the Next button.
- On the Job Details page, enter a Job ID.
- Click the Next button to proceed.
- On the Validation page, click the Next button to view a summary of the job that is about to be created.
- Click the Create job button.
- When the job creation is complete, click the View Results button.
- This will open the Anomaly Explorer where you’ll be able to see the detected anomaly.