Elasticsearch è un motore di ricerca e analisi open source basato su Apache Lucene. Offre ricerca full-text distribuita tramite API REST e documenti JSON.
Prerequisiti
Il pacchetto include una versione di OpenJDK integrata. Se vuoi usare una versione Java personalizzata, installa Java e imposta JAVA_HOME.
Configura il repository
Importa la chiave Elastic:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Versione open source:
cat << EOF > /etc/yum.repos.d/elasticsearch.repo [elasticsearch-7.x] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOF
Installa Elasticsearch
yum install -y elasticsearch-oss systemctl daemon-reload systemctl enable elasticsearch systemctl start elasticsearch
Verifica il servizio:
curl -X GET 'https://localhost:9200'
Configura Elasticsearch
vi /etc/elasticsearch/elasticsearch.yml
Imposta nome cluster e nodo:
cluster.name: els-cluster node.name: els-cluster-node01
Per consentire accessi esterni:
network.host: 0.0.0.0 discovery.seed_hosts: ["192.168.0.10"]
Riavvia:
systemctl restart elasticsearch
Gestisci dati tramite API REST
Aggiungi un documento:
curl -XPUT 'https://localhost:9200/itzgeek/howtos/1' -H 'Content-Type: application/json' -d '{
"Title": "Install Elasticsearch On RHEL 8",
"Date": "May 2019",
"Tag": "RHEL"
}'
Leggi un documento:
curl -X GET 'https://localhost:9200/itzgeek/howtos/1?pretty=true'
Aggiorna un documento:
curl -XPUT 'https://localhost:9200/itzgeek/howtos/1' -H 'Content-Type: application/json' -d '{
"Title": "Install Elasticsearch On RHEL 8",
"Date": "May 2019",
"Tag": "RHEL"
}'
Elimina un documento:
curl -X DELETE 'https://localhost:9200/itzgeek/howtos/1'
La struttura dei dati segue il modello: indice, tipo, documento, campi.