04/01/2020

Elastic Search

Introduction

Elasticsearch est un système de base de données non relationnel

Database => index Table => Type Row => Document

Installation

apt update && apt upgrade && apt install gnupg wget iputils-ping apt-transport-https default-jdk curl
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
apt update
export ES_SKIP_SET_KERNEL_PARAMETERS=true && apt install elasticsearch
systemctl start elasticsearch
systemtl status elasticsearch
systemctl enable elasticsearch

Workaround erreur

To bypass this problem by running Elasticsearch without machine learning functionality set [xpack.ml.enabled: false]

xpack.security.enabled: false
xpack.watcher.enabled: false
xpack.ml.enabled: false
xpack.graph.enabled: false

Pour bug de spawn permission denied :

sed -i 's/PrivateTmp=true/PrivateTmp=false' /usr/lib/systemd/system/elasticsearch.service 

Relancer elasticsearch

systemctl daemon-reload
systemctl restart elasticsearch

Test

Elasticsearch fonctionne comme une API, pour tester faites un GET sur localhost :

curl -G http://localhost:9200

Configuration

Log : /var/log/elasticsearch/elasticsearch.log Config : /etc/elasticsearch/elasticsearch.yml

Le bind ip est une option dans le fichier yml :

http.hosts: 0.0.0.0

J’ai mis 0.0.0.0 ça donne l’accès à tout le monde mais toi met ce que tu veux.

Attention cette option n’est pas indiqué de base, il faut la rajouter en plus

Utilisation

Exemple création d’un utilisateur

curl -X POST "localhost:9200/user/omer?pretty" -H 'Content-Type: application/json' -d'
{
  "password" : "mdp",
  "roles" : [ "admin", "dev" ],
  "full_name" : "Omer Lakraa"
}
'
{
  "_index" : "user",
  "_type" : "omer",
  "_id" : "dEyiu3EB_2SbHoVuCayr",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}
curl -u omer:mdp http://elastic.private:9200/_cluster/health
{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":1,"active_shards":1,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":1,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":50.0}