Skip to content

Instantly share code, notes, and snippets.

@revolunet
Last active August 2, 2019 09:26
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 revolunet/f758449553e454f803e93da1997c8e0a to your computer and use it in GitHub Desktop.
Save revolunet/f758449553e454f803e93da1997c8e0a to your computer and use it in GitHub Desktop.
kali-index.js
version: "3.0"
services:
elasticsearch:
image: elasticsearch:7.2.0
# open ES on local port 9200
ports:
- 9202:9200
# persist ES data when container stops
volumes:
- esdata:/usr/share/elasticsearch/data
- ./docker:/app/docker
command:
- sh
- -c
- "cp /app/docker/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml; ./bin/elasticsearch-plugin list | grep -q analysis-icu || ./bin/elasticsearch-plugin install analysis-icu; docker-entrypoint.sh"
environment:
- http.port=9200
- http.cors.enabled=true
- http.cors.allow-origin=*
- http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
- http.cors.allow-credentials=true
volumes:
esdata:
cluster.name: "code-du-travail-data-elasticsearch"
node.name: "code-du-travail-data-elasticsearch-single-node"
network.host: 0.0.0.0
# Use single node discovery in order for the node to elect itself master and not join a cluster with any other node.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
discovery.type: single-node
# https://github.com/mobz/elasticsearch-head#enable-cors-in-elasticsearch
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: false
xpack.monitoring.enabled: false
xpack.ml.enabled: false
xpack.graph.enabled: false
xpack.watcher.enabled: false
const { Client } = require("@elastic/elasticsearch");
const kali = require("@socialgouv/kali-data/data/index.json");
const serialExec = require("promise-serial-exec");
const client = new Client({ node: "http://localhost:9202" });
const index = async () => {
await client.indices
.delete({
index: "kali"
})
.catch(() => {});
// index each CC sequentially
serialExec(
kali.map(cc => {
const data = require(`@socialgouv/kali-data/data/${cc.id}.json`);
return () =>
client
.create({
index: "kali",
id: data.id,
body: {
...data,
titre: cc.titre
}
})
.catch(r => {
console.log("error", cc.id);
console.log(cc.id, (r.body && r.body.error) || r);
});
})
);
};
index();
// et voila, you can now get http://127.0.0.1:9202/kali/_doc/KALICONT000027343232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment