Skip to content

Instantly share code, notes, and snippets.

@grahamwhaley
Created July 25, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamwhaley/8ba171f95119319dc688fd0cca1c40d5 to your computer and use it in GitHub Desktop.
Save grahamwhaley/8ba171f95119319dc688fd0cca1c40d5 to your computer and use it in GitHub Desktop.
Basic elastic json

Simple elastic/json setup

I've had to do this twice now, as I lost my info from the first time around. So, let's write it down...

Run up elastic in docker

First, let's run up elastic. Elastic give you info on how to do this on their site. I ended up firing a small docker compose:

version: '2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
    container_name: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
volumes:
  esdata1:
    driver: local

Create your index

You need to create your index (database...) before you can inject data into it:

#!/bin/bash

set -x

JSON_URL=192.168.0.111:9200/test1
curl -XPUT "$JSON_URL"

Store your data

And then you can inject data into it:

#!/bin/bash

set -x

json=$(cat myfile.json)
JSON_URL=192.168.0.111:9200/test1/_doc
curl -XPOST -H"Content-Type: application/json" "$JSON_URL" -d "@-" <<< ${json}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment