概要
Docker環境で気軽にElasticsearchの環境を構築し、データを入れるまでのメモです。
Elasticで紹介されているDockerにインストール方法はこちらを参照ください。またDocker Hubはこちらを参照ください。
Dockerにインストール
Dockerファイルとdocker-compose.yamlはこんな感じです。
Dockerfile
FROM docker.elastic.co/elasticsearch/elasticsearch:8.1.0
RUN elasticsearch-plugin install analysis-kuromoji
必要に応じて、kuromoji等のプラグインのインストールが可能です。
docker-compose.yaml
version: '3'
services:
es:
build: ./es
container_name: elasticsearch-v8010
environment:
- node.name=elasticsearch
- discovery.type=single-node
- cluster.name=es-docker-cluster
- "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
- xpack.security.enabled=false
- http.port=9200
ports:
- 9200:9200
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es-data:/usr/share/elasticsearch/data
kibana:
image: docker.elastic.co/kibana/kibana:8.1.0
ports:
- 5601:5601
environment:
ELASTICSEARCH_HOSTS: http://elasticsearch-v8010:9200
volumes:
es-data: null
Dockerファイルをビルドし、起動します。
docker-compose build
docker-compose up -d
Elasticsearchの起動確認をします。
- Elasticsearch
http://localhost:9200 - Kibana
http://localhost:5601/app/home#/
データを入れてみる
Elasticsearchの環境が構築できたのでkibanaのDev Toolsからデータを入れてみます。
まずはmappingを定義します。
PUT sample_index
{
"mappings": {
"properties": {
"item_name":{
"type": "text",
"analyzer": "standard"
}
}
}
}
次にデータを登録します。
POST /sample_index/_bulk
{"index": {"_id": 1}}
{"item_name" : "シャツ"}
{"index": {"_id": 2}}
{"item_name" : "パンツ"}
{"index": {"_id": 3}}
{"item_name" : "帽子"}
登録されていることを確認します。
GET /sample_index/_search
{
"size":10
}