Elastic Search - everjs78/study GitHub Wiki
๊ธฐ๋ณธ
- mapping ์์ ๋ ๋์
- string type์ด๋ฉด ๋ชจ๋ field๊ฐ term/keyword ๋ ๊ฐ ์์ฑ. keyword๋ 256์ด์์ด๋ฉด truncate
- number type์ long
- Text type
- ํํ์ ๋ถ์์ฉ์ด๋ฏ๋ก, aggregation ์ด๋ ์ ๋ ฌ์ด ๋ถ๊ฐ๋ฅ
- Keyword type
- ignore_above 256 ์ด๋ฉด 256์ ๋๋ ๊ฒฝ์ฐ empty๋ก ์ ์ฅ๋๋ฏ๋ก ์กฐ์ฌํ ๊ฒ
- Aggregation
- query์ ๊ฒฐ๊ณผ size์ ๊ด๊ณ์์ด query ์ ์ฒด์ ๋ํด aggregation์ ๋์ํจ
- query ํ ๊ฒฐ๊ณผ์ ๋ํด ์ํ ํ๊ฑฐ๋ query๊ฐ ์์ผ๋ฉด ์ ์ฒด ๋ฌธ์์ ์ํ
- Query Debugging
POST movie/_validate/query?rewrite=true { "query" : {...} }
-
rollup
- index ๋ณ๊ฒฝ๋ ๋ณด๊ธฐ
GET _cat/indices/myinde,rollup?v -
์๋ก์ด index์์ฑ์ mapping์ template์ผ๋ก ๋ถํฐ ์ ์ฉ
- ๋ค์์ nginx-access-log ๋ผ๋ ํ ํ๋ฆฟ์ ์์ฑํ๋ ๊ฒ์ผ๋ก, ์ธ๋ฑ์ค๊ฐ nginx-access-* ์ ํด๋นํ๋ ํจํด์ด๋ผ๋ฉด, ์ง์ ๋ mapping ์ผ๋ก ์ธ๋ฑ์ค๋ฅผ ์์ฑํ๋ค.
ํ ํ๋ฆฟ ์์ฑํ๊ธฐ ๋ค์์ nginx-access-log ๋ผ๋ ํ ํ๋ฆฟ์ ์์ฑํ๋ ๊ฒ์ผ๋ก, ์ธ๋ฑ์ค๊ฐ nginx-access-* ์ ํด๋นํ๋ ํจํด์ด๋ผ๋ฉด, ์ง์ ๋ mapping ์ผ๋ก ์ธ๋ฑ์ค๋ฅผ ์์ฑํ๋ค. ## nginx-access-log ํ ํ๋ฆฟ ์์ฑ curl -X "PUT" "http://my-elasticsearch-server-host:9200/_template/nginx-access-log" \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "index_patterns": [ "nginx-access-*" ], "mappings": { "log": { // type name "properties": { "ip": { "type": "text" }, "host": { "type": "keyword" }, "uri": { "type": "text" }, "datetime": { "type": "date" }, "@timestamp": { "type": "date" } } } ........ } }'
์ฌ์ฉ ์์
-
์์ฑ
- curl -XPUT 'localhost:9200/customer?pretty
-
index ๋ฆฌ์คํธ
- curl -XGET 'localhost:9200/_cat/indices?v'
-
insert 1 document
-
curl -XPOST 'localhost:9200/customer2/info/1?pretty' -H 'Content-Type: application/json' -d '{ "name": "victolee" }'
-
-
๋ชจ๋ index์ size๋ณด๋ ๋ฐฉ๋ฒ
- GET _cat/indices/everjs-2018*,everjs_rollup_idx?v
์ด์
- elasticsearch
sudo docker run -d --restart="always" --name elasticsearch \
-p 9200:9200 \
-p 9300:9300 \
-u 1000 \
-e "discovery.type=single-node" \
-e "bootstrap.memory_lock=true" --ulimit memlock=-1:-1 \
-v `pwd`/data:/usr/share/elasticsearch/data \
-v `pwd`/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v `pwd`/jvm.options:/usr/share/elasticsearch/config/jvm.options \
docker.elastic.co/elasticsearch/elasticsearch:6.7.0
# kibana
sudo docker run -d --restart="always" --name kibana \
-p 5601:5601 \
-e SERVER_NAME=aergo-kibana \
--link elasticsearch:elasticsearch \
-e ELASTICSEARCH_hosts=http://localhost:9200 \
docker.elastic.co/kibana/kibana:6.7.0
# --network=aergo-horde \