Elasticsearchå®éç¨æã®æ³¨æç¹ã¨ã¢ã³ããã¿ã¼ã³ã¾ã¨ã
Elasticsearchå®éç¨æã«å人çã«æ°ãã¤ãã¦ããç¹ãã¾ã¨ãã¾ããã èªåã§ãæ´çã§ãã¦ããªãé¨åãããã¾ãã®ã§ãééã£ã¦ããç¹ã»è¿½å ããæ¹ãè¯ãç¹ãªã©ããã¾ãããæãã¦ããã ããã¨é常ã«å©ããã¾ãã
ç®æ¬¡
- ç®æ¬¡
- ã¤ã³ããã¯ã¹ã»ã¹ãã¼ãè¨å®
- æ¬ä½ã®è¨å®
- æ¤ç´¢é«éå
- ã¤ã³ãã¯ã·ã³ã°é«éå
- ãã¼ã追å ã»åé¤
- çµãã
ã¤ã³ããã¯ã¹ã»ã¹ãã¼ãè¨å®
ã¹ãã¼ããäºåã«å®ç¾©ãã¦ãã
Elasticsearchã¯ã¹ãã¼ãã¬ã¹ãããªãã®ãï¼ã¨ãããªãçªã£è¾¼ã¾ããããªæãã§ãããå人çã«ã¯ãã¼ã¿æå ¥åã«ã¹ãã¼ããå³å¯ã«å®ç¾©ãã¦ããã®ããå§ããã¾ãã
çç±ã¨ãã¦ã¯ã主ã«ä»¥ä¸ã®2ç¹ã§ãã
- ã¹ãã¼ããå®ç¾©ããã«æå ¥ããããã¼ã¿ã¯Elasticsearchãåãå¤æããããã¨ã©ã¼ã®å ã«ãªãããã
- not_analyzedã»doc_valueãªã©ã®è©³ç´°è¨å®(å¾è¿°)ãè¡ã£ãã»ããæ§è½ãè¯ããªã
_allã®ä½¿ç¨ã¯å¿ è¦ãªæã®ã¿è¡ã
ããã©ã«ãã§å ¨ãã£ã¼ã«ãã®ãã¼ã¿ãå ¥ã_allã¨ããã¡ã¿ãã£ã¼ã«ããããã¾ããããã£ã¹ã¯å®¹éã»æ§è½ã®è¦³ç¹ããå ¨ãã£ã¼ã«ããè·¨ãã æ¤ç´¢ãè¡ãäºå®ãç¡ãå ´åã¯ç¡å¹ã«ããã»ããè¯ãã§ãã
{ "mappings" : { "sample_type" : { "_all" : {"enabled" : false} } } }
é¨åä¸è´æ¤ç´¢ãããªãstringãã£ã¼ã«ãã«ã¯not_analyzedãã¤ãã
stringãã£ã¼ã«ãã¯ããã©ã«ãã§ã¯ã¤ã³ããã¯ã¹æã«å½¢æ ç´ è§£æãªã©ã®å¦çãè¡ããã¦ãã¾ããããå®å ¨ä¸è´æ¤ç´¢æã«æ³å®ããªãçµæãè¿ã£ã¦ãããã¤ã³ããã¯ã¹å¦çãéããªã£ãããã¦ãã¾ãã¾ãã
å®å ¨ä¸è´æ¤ç´¢ã®ã¿ãè¡ãããstringãã£ã¼ã«ãã«å¯¾ãã¦ã¯ããããã³ã°æã«not_analyzedãã¤ãããã¨ãæ¨å¥¨ãã¾ãã
"string_field" : { "type" : "string", "index" : "not_analyzed" }
doc_value:trueãã¤ãã
ãããã³ã°ã®éã«doc_values:trueãè¨å®ããã¨ãcacheãã¡ã¢ãªã§ã¯ãªããã£ã¹ã¯ã«ä¹ãããã¨ãã§ãã¾ããã¡ã¢ãªã«ä¹ããå ´åããã20%ç¨ä½éã«ãªãã¾ããããã¼ãã¡ã¢ãªã«å½±é¿ãããªããªããæåãå®å®ããã®ã§ãªã¹ã¹ã¡ã§ãã
ãªããnot_analyzedã§ã¯ãªãstringãã£ã¼ã«ãã«ã¯é©ç¨ã§ããªãã®ã§æ³¨æãã¦ãã ããã
Disk-Based Field Data a.k.a. Doc Values | Elastic
"string_field" : { "type" : "string", "index" : "not_analyzed", "doc_values":true }
ã§ããã ãã¨ã¤ãªã¢ã¹ã使ã
ã¢ããªããã¤ã³ããã¯ã¹ãåç §ããéã«ãã¤ã³ããã¯ã¹åãç´æ¥åç §ããã®ã§ã¯ãªãã¨ã¤ãªã¢ã¹ãè¨å®ãã¦ãã¡ããåç §ãããã¨ã§ãå¤æ´ã«å¼·ããªãã¾ãã
ä¸è¬çã«æ¤ç´¢ä»æ§ã®å¤æ´ãªã©ãè¡ãéã¯ã¤ã³ããã¯ã¹åä½æãè¡ãå¿ è¦ãããã®ã§ãããã¨ã¤ãªã¢ã¹ãå©ç¨ããã°ãã¦ã³ã¿ã¤ã ç¡ãã§æè»ã«å¯¾å¿ãããã¨ãã§ãã¾ãã
Changing Mapping with Zero Downtime | Elastic
Elasticsearch インデックス・エイリアス – Hello! Elasticsearch. – Medium
Elasticsearch のインデックスを無停止で再構築する - クックパッド開発者ブログ
以ä¸ã¯ãtest_indexã«ç´ä»ãã¦ããã¨ã¤ãªã¢ã¹ãtest_index_2ã«åãæ¿ããéã®ã³ãã³ãã§ããã¢ããªããã¯å¸¸ã«test_index_aliasãåç §ããããã«ãã¦ããã°ããã¦ã³ã¿ã¤ã ç¡ãã§ã¢ããªããæ°ããindexãåç §ã§ããããã«ãªãã¾ãã
curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ {"remove": {"index": "test_index", "alias": "test_index_alias" }}, {"add": {"index": "test_index2", "alias": "test_index_alias" }} ] }'
å¿ è¦ã«å¿ãã¦ã«ã¼ãã£ã³ã°ãè¡ã
ããã©ã«ãã§ã¯ãã¼ã¿ãã©ã®ã·ã£ã¼ãã«é ç½®ããããã¯idã®ããã·ã¥å¤ãã·ã£ã¼ãç·æ°ã§å²ã£ãå¤ã§æ±ºå®ããã¾ããããããã³ã°æã«ä»»æã®ãã£ã¼ã«ãã_routingã«æå®ããäºã§ããã®ãã£ã¼ã«ãã®å¤ã«ãã£ã¦ã·ã£ã¼ãã®é ç½®ã決ãããã¨ãã§ãã¾ãã
é©åã«è¨å®ããã¨æ¤ç´¢æã®è² è·ãæ¸ãããã¨ãã§ãã¾ãããä¸é©åãªãã£ã¼ã«ããæå®ããã¨ãããã·ã£ã¼ããçã¾ãã¦ãã¾ãã®ã§æ³¨æãã¦è¨å®ãã¦ãã ãããèªä¿¡ãç¡ããªãããã©ã«ãè¨å®ã®ã¾ã¾ã§è¯ãã§ãã
対象ã®ãã£ã¼ã«ãã¯ãstore:trueãã¤index:not_analyzedã§ããå¿ è¦ãããã¾ããã¾ããrequired:trueã§ãªãã¦ã¯ãªãã¾ããã
_routing field | Elasticsearch Reference [6.1] | Elastic
{ "mappings" : { "sample_type" : { "_routing" : {"required" : true, "path" : "route_param"}, "properties" : { ã "route_param" : { "type" : "string", "index" : "not_analyzed", "required" : "true", "store" : true } } } } }
æ¬ä½ã®è¨å®
ãã¼ãã¡ã¢ãªãé©åã«è¨å®ãã
å ¬å¼ã«æ¸ãã¦ããéãããã¼ãã¡ã¢ãªã¯ç©çã¡ã¢ãªã®ååã¾ã§ã§32GBãè¶ ããªãããã«ãã¾ãããã
Heap: Sizing and Swapping | Elasticsearch: The Definitive Guide [2.x] | Elastic
/etc/sysconfig/elasticsearch
ES_HEAP_SIZE:4g
ã¹ã¯ããããªãããã«è¨å®
å ¬å¼ã§ãèµ·åæã«ã¡ã¢ãªã確ä¿ããã¹ã¯ããããªãããã«ãããã¨ããè¨å®ãæ¨å¥¨ããã¦ãã¾ãã
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html
èµ·åæã®ã¡ã¢ãªç¢ºä¿ã¯ä¸ã«æ¸ããES_HEAP_SIZEã®è¨å®ã§OKãªã®ã§ãå¾ã¯ã¹ã¯ããããªãããã«ããè¨å®ãè¡ãã¾ãã
/etc/elasticsearch/elasticsearch.yml
bootsrap.mlockall:true
ç°å¢ã«ãã£ã¦ä¸æããããªãæãããã®ã§ãè¨å®ãå¹ãã¦ãããã©ããhttp://localhost:9200/_nodes/process?prettyãè¦ã¦ç¢ºèªãã¾ãããã
ä¸æããããªãæã¯ä»¥ä¸ã®è¨äºãè¦ã¦ã¿ã¦ãã ããã
ElasticSearchでmlockall:trueが効かない時にチェックすること - サナギわさわさ.json
ã¹ããªãããã¬ã¤ã³å¯¾çãè¡ã
ã¹ããªãããã¬ã¤ã³å¯¾çã®ããã«ããã¹ã¿ã¼ãã¼ããé¸ã¶éã«å¿
è¦ã¨ãªãæ¥ç¶ãã¼ãã®æ°ããã¼ãæ°/2+1
ã«è¨å®ãã¦ããã¾ããããä¾ãã°6å°æ§æã®å ´åã¯4ã«ãªãã¾ãã
/etc/elasticsearch/elasticsearch.yml
discovery.zen.minimum_master_nodes:4
curlããè¨å®ããå ´åã¯ãã£ã¡
curl -XPUT http://localhost:9200/_cluster/settings -d '{ "persistent": {"discovery.zen.minimum_master_nodes": 4} }'
field data cacheã«ä¸éãä¸ãã
Elasticsearchã§ã¯åfieldã®ãã¼ã¿ãã¡ã¢ãªã«è¼ãããã¨ã§æ¤ç´¢ãé«éåãã¦ããã®ã§ãããããã©ã«ãã§ã¯ç¡å¶éã«ã¡ã¢ãªã«è¼ããããOutOfMemoryErrorãçºçãããã¨ãããã¾ãã 以ä¸ã¯ã使ç¨å¯è½ãªã¡ã¢ãªãHEAP_SIZEã®75%ã«å¤æ´ããä¾ã§ãã
/etc/elasticsearch/elasticsearch.yml
indices.fielddata.cache.size: 75%
æ¤ç´¢é«éå
Warmerãç»é²ãã
åfieldã®ãã¼ã¿ãã¡ã¢ãªã«è¼ããã¨ã§æ¤ç´¢ãé«éåãããã®ã¯ä¸è¿°ããéãã§ãããfieldã®ãã¼ã¿ãã¡ã¢ãªã«è¼ããå¦çã¯ã¤ã³ããã¯ã¹åæ§ç¯å¾1åç®ã®ã¯ã¨ãªãæããããæã«è¡ãããããã1åç®ã®ã¯ã¨ãªãããªãéããªããã¨ãå¤ãã§ãã
Warmerã¯ã¨ãªãè¨å®ãã¦ããã¨ãã¤ã³ããã¯ã¹åæ§ç¯å¾ã«èªåã§ã¯ã¨ãªãçºè¡ãã¦field cacheãä½æãã¦ãããã®ã§ä¾¿å©ã§ãã
Warmers | Elasticsearch Reference [6.1] | Elastic
curl -XPUT localhost:9200/testindex/_warmer/warmer_1 -d '{ "query" : { "match_all" : {} }, "aggs" : { "aggs_1" : { "terms" : { "field" : "field" } } } }'
queryã¨filterã使ãåãã
æ¡ä»¶æ¤ç´¢ã¯queryã§ãfilterã§ãè¡ãã¾ãããã¹ã³ã¢è¨ç®ãç¨ããªãæ¤ç´¢æ¡ä»¶ï¼å®å ¨ä¸è´ãrangeãªã©ï¼ãªãqueryã§ã¯ãªãfilterãç¨ããæ¹ãæ©ãã§ãã
Optimizing Elasticsearch Searches | Elastic
filterã®ãã£ãã·ã¥è¨å®ã使ãåãã
filterã使ãã¨ãã£ã«ã¿ã§å¼ã£ããã£ããªã¯ã¨ã¹ããããã©ã«ãã§ãã£ãã·ã¥ãã¦ããã¾ãã
ãã å ¨ã¦ãã£ãã·ã¥ãã¦ããã¨ã¡ã¢ãªã足ããªããªãäºãå¤ãã®ã§ãæããã«ãã£ãã·ã¥ããªãæ¹ãè¯ãçµãè¾¼ã¿æ¡ä»¶ã«é¢ãã¦ã¯æ¤ç´¢ã®éã«ãã£ãã·ã¥ããªãããã«æ示çã«è¨å®ãã¾ãããã
å¿ è¦ç¡ããã£ã¼ã«ãã¯æ¤ç´¢ã®éã«åå¾ããªã
è¨ãã¾ã§ãç¡ãã§ããããã
ã¤ã³ãã¯ã·ã³ã°é«éå
å°ã£ããå ¬å¼ãè¦ã¾ãããã
Performance Considerations for Elasticsearch Indexing | Elastic
ãã¨ä»¥ä¸ã®è¨äºã«ã»ã¨ãã©ã¾ã¨ã¾ã£ã¦ããã®ã§ã詳ããã¯ãã¡ããè¦ãæ¹ãè¯ãããããã¾ããã
Elasticsearchインデクシングパフォーマンスのための考慮事項 - Qiita
bulk APIã使ã
大è¦æ¨¡ãã¼ã¿ã®æå ¥ã«ã¯å¿ ãbulk APIã使ãã¾ãããããªããå ¬å¼ã§ã¯1ã¤ã®bulk Importã®ãµã¤ãºã¯5~15MBã«ãããã¨ãæ¨å¥¨ãã¦ãã¾ãã
curl -XPOST http://localhost:9200/_bulk --data-binary @databatch.json >/dev/null
ã³ãããé »åº¦ã®å¤æ´
ElasticSearchã¯NRT(Near Real-Time Search)æ©è½ãæè¼ãã¦ãããããã©ã«ãã§1ç§ãã¨ã«ã½ããã³ããããå®è¡ãããæ´æ°çµæãæ¤ç´¢ã«åæ ããã¾ãã
ã¤ã³ãã¯ã·ã³ã°æã«ã¯ãããçµæ§éããããæ´æ°çµæãããã¾ã§ãªã¢ã«ã¿ã¤ã ã«åæ ããå¿ è¦ããªãå ´åã¯ãã½ããã³ãããã®é »åº¦ã¯30sãããã«è¨å®ããæ¹ãæ©ããªãã¾ãã
curl -XPUT http://localhost:9200/testindex/_settings -d ' { "index" : { "refresh_interval" : "30s" } }'
ã¬ããªã«ã·ã£ã¼ããä¸æçã«0ã«è¨å®
ã¤ã³ãã¯ã·ã³ã°ä¸ã®ã¿ã¬ããªã«ã·ã£ã¼ããä½ããªãããã«ãããã¨ã§ã ãã¼ã¿æå ¥ã«ãããæéãçããªãã¾ãããªã¹ã¯ã¨ã®ãã¬ã¼ããªãã§ãã
curl -XPUT http://localhost:9200/testindex/_settings -d ' { "index" : { "number_of_replicas" : 0 } }'
ãã¼ã追å ã»åé¤
ãã¼ã追å ã»åé¤æã¯ã¹ããªãããã¬ã¤ã³ãèµ·ãããããã®ã§æ³¨æãã¦ãªãã¬ã¼ã·ã§ã³ãã¾ããããã¾ãããªãã¬ã¼ã·ã§ã³å¾ã«discovery.zen.minimum_master_nodes
ãå¤æ´ããã®ãå¿ããªãããã«ãã¦ãã ããã
ã·ã£ã¼ãã®èªåé ç½®ãåæ¢
ãã¼ãã®è¿½å ã»åé¤å¦çãè¡ãéã«ãããã©ã«ãã ã¨ã·ã£ã¼ãã®åé ç½®ãèµ°ã£ã¦è² è·ãä¸æ°ã«ä¸ããã¾ããå¦çã®åã«ã·ã£ã¼ãã®èªåé ç½®ãåæ¢ãã¦ããã¾ãããã
Elasticsearchのクラスタにノードを追加するときにやっていること - すずけんメモ
curl -XPUT http://localhost:9200/_cluster/settings -d '{ "persistent": {"cluster.routing.allocation.enable": "none"} }'
ã¡ãªã¿ã«ãªãã¬ã¼ã·ã§ã³çµäºæã«èªåé ç½®ãæå¹ã«æ»ãå ´åã¯ä»¥ä¸ã§ãã
curl -XPUT http://localhost:9200/_cluster/settings -d '{ "persistent": {"cluster.routing.allocation.enable": "all"} }'
ã·ã£ã¼ããæåã§åé ç½®
ãã¼ã追å ã®éã¯ä»¥ä¸ã®ãªãã¬ã¼ã·ã§ã³ã§åé¡ããã¾ãããã
- ã·ã£ã¼ãã®èªåé ç½®ãåæ¢
- ãã¼ãã追å
- ã·ã£ã¼ãã®èªåé ç½®ãæå¹ã«æ»ã
ãã¼ãåé¤ã®éã¯ä¸æé å¢ãã¾ãã
- ã·ã£ã¼ãã®èªåé ç½®ãåæ¢
- åé¤å¯¾è±¡ãã¼ãããã·ã£ã¼ãã移å
- ãã¼ããåé¤
- ã·ã£ã¼ãã®èªåé ç½®ãæå¹ã«æ»ã
ã·ã£ã¼ãã®æååé ç½®ã¯ä»¥ä¸ã®ããã«ãã¦è¡ãã¾ããé¢åã§ãã1ã¤ãã¤ç§»åãããã®ããå§ããã¾ãã
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands" : [ { "move" : { "index" : "test", "shard" : 0, "from_node" : "node1", "to_node" : "node2" } } ] }'
çµãã
以ä¸ã§ããåé ã«ãæ¸ãã¾ãããééã£ã¦ããç¹ã»è¿½å ããæ¹ãè¯ãç¹ãªã©ããã¾ãããæãã¦ããã ããã¨å©ããã¾ãï¼
å¼ç¤¾ã§ã¯ç¾å¨ã¨ã³ã¸ãã¢ãåéä¸ã§ãï¼