ã¿ãªããããã«ã¡ã¯ããã¸ãµã¯ã§ããååã®è¨äºã§ãä¼ããã¦ããElasticsearchã®æ¤è¨¼ãã²ã¨æ®µè½ãã¾ããã®ã§ãæ¤è¨¼çµæãã¬ãã¼ããããã¾ãã
é£è¼ç®æ¬¡
- ãå ¨ææ¤ç´¢ ã Elasticsearchã¨ãã¼ã¿å¿ååææ³ã
- ãå ¨ææ¤ç´¢ã®æ¢æ± Elasticsearch(1) ã: ããã¸ã§ã¯ãæ¹éããã³Elasticsearchæ¦è¦
-
大éãã¼ã¿ãæ¤ç´¢ãããµã¼ãã¹ã§Elasticsearchã¯RDBã®ä»£æ¿åè£ã«ãªããããï¼(Elasticsearch vs pg_bigm)ã âä»èªãã§ããè¨äº
-
ãã¼ã¿å¿åå 第1åï¼å¿ååãããå人æ å ±ã¨ã¯ä½ãªã®ã
- ãã¼ã¿å¿åå 第2åï¼å人æ å ±ã¯å¿ååãã¦ãæå³ããªãã®ã§ã¯ãªããï¼
- ãã¼ã¿å¿åå 第3åï¼å人æ å ±ãå¿ååããããã»ã¹
- ãã¼ã¿å¿åå 第4åï¼å¿ååã®ããã«è¡ããã¼ã¿é ç®ã®ä¸è¬åã¨ã¯
- ãã¼ã¿å¿åå 第5åï¼ãã¼ã¿å¿ååã®ææ¨
- ãã¼ã¿å¿åå 第6åï¼å®éã®å¿åå
ã¯ããã«
æ¤è¨¼ãè¡ãã«ããããç§ãã¡ã¯ååã以ä¸ã®éãã´ã¼ã«è¨å®ããã¾ããã
ãæ¤ç´¢æ©è½ãæããæ°è¦ãµã¼ãã¹ã®ã¢ã¼ããã¯ãã£æ¤è¨æ®µéã§ãRDBã ãã§ãªãElasticseachãæ¯è¼æ¤è¨ææã¨ãã¦æããç¶æ ãä½ãã
ãã®æ¤è¨¼ãè¡ãã«ãããã以ä¸ã®ãããªãµã¼ãã¹ãã¢ãã«ã¨ãã¦è¨å®ãã¾ããã
- æ±ããã¼ã¿ã®ã¬ã³ã¼ãæ°ã¯ãå¤ãã¦ã100ä¸ä»¶ãªã¼ãã¼
â»å½ç¤¾ã¯BtoBåãã®ãµã¼ãã¹ããã¤ä¸å°ä¼æ¥ã®ã客æ§ã主ãã顧客層ã¨ãã¦ããã®ã§ã1顧客ã§ã¦ã³åä¸ä»¶ãã¦ã³å件ã¨ãããããªã¬ã³ã¼ããçºçããã±ã¼ã¹ããã¯ä¸è¨ç¨åº¦ã®ãã¼ã¿éãæ¤è¨¼å¯¾è±¡ã¨ãã¦ã¯å¦¥å½ã ããã¨å¤æãã¾ããã - ããã¹ããã¼ã¿ã«å¯¾ãããä¸éä¸è´æ¤ç´¢ï¼ããããLIKEæ¤ç´¢ï¼æ©è½ãæã¤
â»å¾æ¥ã®æè¡é åã代æ¿ãããã®ãã¨ããä½ç½®ä»ãã§RDBã§ããã©ã¼ãã³ã¹å£åãçºçããã¡ãªä¸éä¸è´æ¤ç´¢ãæ¡ç¨
ã¾ããå½ç¤¾ã§ã¯RDBã«PostgreSQLãæ¡ç¨ããå ´åãå¤ãã®ã§ãããããã©ã«ãã®PostgreSQLã§ã¯æ¯è¼ã®ä½å°ããªãã®ã§ãPostgreSQLã®å ¨ææ¤ç´¢ãã©ã°ã¤ã³ã§ããpg_bigmãæ¯è¼å¯¾è±¡ã¨ãã¦æ¡ç¨ãããã¨ã«ãã¾ããã
çµè«ããè¨ãã¨â¦
- ãå¾æ¥åã®LIKEæ¤ç´¢ãè¡ã代æ¿æ段ãã¨ãã¦ã¯ãé度ã»æ©è½é¢ã§Elasticsearchã¯åè£ã«ãªãããããããããã®ç®çã ãã§ããã°ãpg_bigmãæ¡ç¨ããã»ãããã¡ãªãããå°ãªããããããElasticsearchãå°å ¥ããå¿ è¦ã¯ç¡ãã
- Elasticsearchãæ¡ç¨ããã®ã§ããã°ãå½¢æ ç´ åã¤ã³ããã¯ã¹ã®ç¹å¾´ãæ´»ããããèªç¶ãªææ¸æ¤ç´¢ãããããã¾ãæ¤ç´¢ãããã¹ã±ã¼ã©ããªãã£ããªã©ã®è¦ä»¶ãéè¦ããã¹ãã§ããã
- ããããé¸æãããã¯ãæ©è½è¦ä»¶ã»ç¨éãããã¼ã¿ã®ç¹æ§ã«å¿ãã¦é¸æããã¹ãã§ããã
以ä¸ãä¸è¨çµè«ã«è³ã£ãæ¤è¨¼çµæãã覧ãã ããã
ãã¼ã¿ã¹ãã¢ã¨ãã¦ã®æ¯ãèãã®ç¹å¾´
æ¤è¨¼çµæããä¼ãããåã«ãElasticsearchã®ãã¼ã¿ã¹ãã¢ã¨ãã¦ã®ç¹å¾´ã確èªãã¦ããã¾ãããã
ããã¥ã¡ã³ãåãã¼ã¿ãã¼ã¹ã§ãã
- ElasticSearchã¯ããã¥ã¡ã³ãåãã¼ã¿ãã¼ã¹ã§ãèªç±ãªã¬ã¤ã¢ã¦ãã§ã®ãã¼ã¿è¡¨ç¾ãå¯è½ã§ããã¹ãã¼ãã«ã¨ãããããæ§ã ãªå½¢å¼ã®ææ¸ãã¼ã¿ã横æçã«æ¤ç´¢ãããã¨ã«åªãã¦ãã¾ãã
ã¹ã±ã¼ã©ãã«
- Elasticsearchã¯ãã¼ã¿ã»ãããåå²ã®æå°åä½ã¨ãªãã·ã£ã¼ãã«åããè¤æ°ã®ãã¼ãã«ã·ã£ã¼ããåæ£ãã¦é ç½®ãã¾ããã·ã£ã¼ããåçã«åé ç½®ãããã¨ã§æè»ã«ã¹ã±ã¼ã«ã¢ã¦ãããããã¨ãã§ãã¾ãã
ãã©ã³ã¶ã¯ã·ã§ã³ããªã
- Elasticsearchã«ã¯ãã©ã³ã¶ã¯ã·ã§ã³ãããã¾ããããã¼ã¿ã®ç»é²ã«å¤±æãããç»é²ä¸ã«ä»ããã»ã¹ããæ¤ç´¢ãããã£ããã¨ãã£ãACIDæ§ãæ±ããããå±é¢ã§ã¯å¥éèæ ®ãå¿ è¦ã§ãã
çµåã¯ä¸å¾æ
- åè¿°ã®éããElasticsearchã¯è¤æ°ã®ãã¼ãï¼ããã³ã·ã£ã¼ãï¼ã«ãã¼ã¿ã»ãããåæ£ãã¦ä¿æãã¾ãããã®ç¹æ§ãããRDBã«ãããæ£è¦åãçµåã¨ãã£ã使ãæ¹ã«ã¯é©ãã¦ãã¾ããã
- ã¾ããã¤ã³ããã¯ã¹éã®çµåãè¡ãæ©è½ã¯ãªãï¼éå®çã«ã親åé¢ä¿ã§ã®çµåãè¡ããã¨ã¯ã§ããï¼ãåºæ¥ãã ãéæ£è¦åãããã¨ãæ¨å¥¨ããã¦ãã¾ãã
ããããç¹å¾´ããåç´ã«RDBã®ä»£æ¿ã¨ãã¦æ¡ç¨ããã¨ããããã¯ã大éã®ææ¸ãé«éã«æ¤ç´¢ãããã¨ã«é©ããä»çµã¿ãæ´»ããã¦ãéå®çã«ä½¿ç¨ããã®ãè¯ãã§ãããã
æ¤è¨¼ï¼PostgreSQLã®LIKEæ¤ç´¢ã¨åãæ¤ç´¢çµæãå¾ããã¨ãã§ããã
Elasticsearchã使ç¨ããå ´åã§ããPostgreSQLã®LIKEæ¤ç´¢ã¨åæ§ã®çµæãå¾ããã¨ãã§ããã®ã§ããããã
çµè«ããè¨ãã°ãPostgreSQLã®LIKEæ¤ç´¢ã¨åæ§ã®æ¤ç´¢çµæãå¾ããã¨ãã§ãããã¨ãåããã¾ããã
ãã ããAnalizerã«ã¤ãã¦ã®åæç¥èã¨ãã®ç¹æ§ã«ã¤ãã¦ç解ããããã§ãmatch_phraseã¯ã¨ãªã使ç¨ããå¿
è¦ãããã¾ãã
Analizerã¨ã¯
Elasticsearchã«ããããææ¸ãã¼ã¿ãããã³æ¤ç´¢ã¯ã¨ãªæååãå解ã»å å·¥ãããã¨ã§å¹çããæ¤ç´¢ãè¡ãããã®ä»çµã¿ã
ææ¸ãã¼ã¿ãã¤ã³ããã·ã³ã°ããéããä¸å®ã®ã«ã¼ã«ãã«å¾ã£ã¦æååãåå²ããã
æ¤ç´¢ã¯ã¨ãªã«å¯¾ãã¦ãåãã«ã¼ã«ã§æååãåå²ããåå²ãããç¶æ
ã§æ¤ç´¢ãè¡ããããï¼ãã¤ããã¤æ¢ç´¢ãè¡ãã®ã«æ¯ã¹ã¦ãé«éã«æ¤ç´¢ãè¡ããã¨ãã§ããã
ãã®ããä¸å®ã®ã«ã¼ã«ããå¸ãã®ãTokenizerã¨å¼ã°ãããã®ã§ãå½¢æ
ç´ è§£æåãN-Gramåï¼æååãNæåé·åå²ããï¼ãªã©ãããã
ææ¸ãã¼ã¿ãã©ãæ±ãããã®ãã«ãã£ã¦ãã©ã®ãããªAnalizerãé¸æãããã決å®ããå¿
è¦ãããã
å½¢æ ç´ è§£æåãç¨ããAnalizer(Kuromoji Analysis Plugin)ã®å ´å
å½¢æ ç´ è§£æåãç¨ããå ´åããå ¨ææ¤ç´¢ã¨ã³ã¸ã³ãã¨ããæååã¯æ¬¡ã®ããã«åå²ããã¾ãã
curl -X POST -k -H 'Content-Type: application/json' '/_analyze' --data '{ "analyzer" : "kuromoji", "text" : "å ¨ææ¤ç´¢ã¨ã³ã¸ã³" }'
{ "tokens": [{ "token": "å ¨æ", "start_offset": 0, "end_offset": 2, "type": "word", "position": 0 }, { "token": "æ¤ç´¢", "start_offset": 2, "end_offset": 4, "type": "word", "position": 1 }, { "token": "ã¨ã³ã¸ã³", "start_offset": 4, "end_offset": 8, "type": "word", "position": 2 }] }
N-gramåã®Analizerã®å ´å
N-gramåãç¨ããå ´åããå ¨ææ¤ç´¢ã¨ã³ã¸ã³ãã¨ããæååã¯æ¬¡ã®ããã«åå²ããã¾ãã ãªããæ¤è¨¼ã«ä½¿ç¨ããAmazonESã«ã¯ãN-gramåã®Analyzerãããã¾ããã®ã§ãèªåã§Tokenizerãæå®ãã¦ã«ã¹ã¿ã Analyzerãå®ç¾©ãã¦ãã¾ãã
curl -X PUT -k -H 'Content-Type: application/json' '/bigram' --data '{ "index":{ "analysis":{ "tokenizer" : { "bigram" : { "type": "nGram", "min_gram" : 2, "max_gram" : 2, "token_chars": [ "letter", "digit" ] } }, "analyzer" : { "bigram" : { "type" : "custom", "tokenizer" : "bigram" } } } } }'
curl -X POST -k -H 'Content-Type: application/json' '/bigram/_analyze' --data '{ "analyzer" : "bigram", "text" : "å ¨ææ¤ç´¢ã¨ã³ã¸ã³" }'
{ "tokens": [{ "token": "å ¨æ", "start_offset": 0, "end_offset": 2, "type": "word", "position": 0 }, { "token": "ææ¤", "start_offset": 1, "end_offset": 3, "type": "word", "position": 1 }, { "token": "æ¤ç´¢", "start_offset": 2, "end_offset": 4, "type": "word", "position": 2 }, { "token": "ç´¢ã¨", "start_offset": 3, "end_offset": 5, "type": "word", "position": 3 }, { "token": "ã¨ã³", "start_offset": 4, "end_offset": 6, "type": "word", "position": 4 }, { "token": "ã³ã¸", "start_offset": 5, "end_offset": 7, "type": "word", "position": 5 }, { "token": "ã¸ã³", "start_offset": 6, "end_offset": 8, "type": "word", "position": 6 }] }
ä¸è¨ã«ããã¦ãä¾ãã°ãã¨ã³ã¸ãã¨ãããã¼ã¯ã¼ãã§æ¤ç´¢ãè¡ã£ãå ´åãå½¢æ ç´ åã®Analizerãç¨ããå ´åã¯HitãããN-granåã®Analyzerãç¨ããå ´åã¯Hitãã¾ãã
ãããElasticsearchããRDBã®ä»£æ¿ã¨ãã¦LIKEæ¤ç´¢ã¨åçã®æ¤ç´¢ãè¡ãã®ã§ããã°ãN-gramåã®Analyzerã使ç¨ãããã¨ã§å®ç¾ã§ãã¾ãã
ä¸æ¹ã§ãå½¢æ
ç´ åã®Analyzerã使ç¨ããæ¹ããæ¤ç´¢çµæã¨ãã¦ã¯ããèªç¶ãªæ¤ç´¢çµæãå¾ããã¨ãã§ãã¾ãã
ä»åã¯ãLIKEæ¤ç´¢ã®ä»£æ¿ã¨ãã観ç¹ã§æ¤è¨¼ããããN-gramåãæ¡ç¨ãã¾ããããAnalyzerã®é¸æã«ã¤ãã¦ã¯ãæ¬æ¥ã¯ä¸è¨ã®åºæºã§é¸ã¶ãã¨ã«ãªãã¾ãã
- 確å®ã«ãã¼ã¯ã¼ããå«ã¾ããæ¤ç´¢çµæãå¾ããå ´åãâ N-gramå
- åãæ¼ãããããããèªç¶ãªçµæãå¾ããå ´åãâãå½¢æ ç´ å
ãªããElasticsearchã¯ãè¤æ°ã®Analyzerãè¤åçã«ç¨ãããã¨ãã§ãã¾ãããããã«ã¤ãã¦ã¯ä»åã®æ¤è¨¼å 容ããã¯å¤ãã¦ãã¾ãã
match_phraseã¯ã¨ãª
Elasticsearchãç¨ãã¦å ¨ææ¤ç´¢ãå®è¡ããéãã©ã®ãããªåãåãããå®è¡ããããæå®ãããã¨ãã§ãã¾ãã
match
ã¯ã¨ãªã¯ãæå®ããã¯ã¨ãªæååãAnalizerã«ãã£ã¦å解ããããããã®ãã¼ã¯ã³ã®é åºã«ãããããã¼ã¯ã³ãå«ã¾ãã¦ãããã©ãã
ã«ãã£ã¦æ¤ç´¢çµæãå°åºãã¾ãã
GET /_search { "query": { "match" : { "message" : { "query" : "å ¨ææ¤ç´¢ã¨ã³ã¸ã³" } } } }
ä¾ãã°ããå
¨ææ¤ç´¢ã¨ã³ã¸ã³ãã¨ãããã¼ã¯ã¼ãã§åãåãããè¡ã£ãæãAnalyzerã«Kuromojiã使ç¨ãã¦ããã°ãæ¤ç´¢ãã¼ã¯ã¼ãã¯å
¨æ
ãæ¤ç´¢
ãã¨ã³ã¸ã³
ã¨ããï¼ã¤ã®ãã¼ã¯ã³ã«åå²ããã¾ãã
ãã®æããå
¨ææ¤ç´¢ã¨ã³ã¸ã³ã¨ã¯ãã¨ããæç« ã ãã§ãªãããã¨ã³ã¸ã³
ãå
¨æ
ãæ¤ç´¢
ãã¾ããã¨ããæç« ããæ¤ç´¢çµæã«Hitãã¾ãã
ä¸æ¹ãLIKEæ¤ç´¢ã®ãããªä¸éä¸è´æ¤ç´¢ã«Elasticsearchã使ç¨ãããå ´åã¯ãmatch_phrase
ã¯ã¨ãªã使ç¨ããå¿
è¦ãããã¾ãã
GET /_search { "query": { "match_phrase" : { "message" : { "query" : "å ¨ææ¤ç´¢ã¨ã³ã¸ã³" } } } }
match_phraseã¯ã¨ãªã¯ãããããã®ãã¼ã¯ã³ã®é åºã»åºç¾ä½ç½®ãä¸è´ãã
ãã®ãæ¤ç´¢çµæã«å°åºãã¾ãã
ã§ãããããå
¨ææ¤ç´¢ã¨ã³ã¸ã³ã¨ã¯ãã¨ããæç« ã¯Hitãã¾ããããã¨ã³ã¸ã³ãå
¨æãæ¤ç´¢ãã¾ãããããå
¨æãæ¤ç´¢ããã¨ã³ã¸ã³ã§ããã¨ãã£ãæç« ã¯Hitãã¾ããã
æ¤è¨¼ï¼PostgreSQL(pg_bigm)ã¨æ¯è¼ãã¦ã©ãã ãã®æ¤ç´¢æ§è½ãçºæ®ã§ããã
次ã«ãElasticsearchã¨pg_bigmã®æ¤ç´¢é度ã®æ¯è¼ã«ããæ¤ç´¢æ§è½ã®æ¤è¨¼çµæãè¦ã¦ããã¾ãããã
pg_bigmã¨ã¯ï¼
- PostgreSQLä¸ã§åä½ããæ¥æ¬èªã«å¯¾å¿ããå ¨ææ¤ç´¢ç¨ã¢ã¸ã¥ã¼ã«
- N-gramæ¹å¼ã§ã2æååä½ã§åå²ãã
- ã¤ã³ã¹ãã¼ã«ãã¤ã³ããã¯ã¹ã®æ§ç¯ã容æ
- SQLããã®ã¾ã¾å©ç¨ã§ãã
- å ¬å¼ããã¥ã¡ã³ã
æ¤è¨¼ã«ä½¿ç¨ãããã¼ã¿ãããã³ãã¼ã¿é
- Wikipediaã®æ¥æ¬èªçå ¨ãã¼ã¿
- ãã¼ã¿ä»¶æ°ï¼ç´230ä¸ä»¶
è¨æ¸¬æ¹æ³
- ç¡ä½çºã«é¸å®ãããã¼ã¯ã¼ã群ããã©ã³ãã ã«é¸å®ãããã¼ã¯ã¼ããç¨ãã¦1000ååãåãããè¡ããåãåããã«è¦ããæéï¼ãããã¯ã¼ã¯çµè·¯ã«ä¿ãæéãªã©ãé¤ãï¼ã¨ã対象ã®ãã¼ã¯ã¼ãã§Hitããæç« ã®æ°ãã°ã©ãã«ãããããã
- Elasticsearchãpg_bigmãé©ç¨ããPostgreSQLãç¡èª¿æ´ï¼B-treeã¤ã³ããã¯ã¹ï¼ã®PostgreSQLã®ï¼è ã«å¯¾ãã¦åæ§ã®æ¤ç´¢ãè¡ããã°ã©ããæ¯è¼ãã
è¨æ¸¬ã«ä½¿ç¨ããç°å¢
- ããããã®æ¤è¨¼ã«ä½¿ç¨ããç°å¢ããã³ã¹ããã¯ã«ã¤ãã¦ã¯ä¸è¨ã®éãã§ãããªããElasticsearchã¯æå°æ§æã§ã3ãã¼ããè¦ãããããElasticsearchãPostgreSQLãããã¥ã¼ãã³ã°ã«ãã£ã¦æ§è½ãå¤ãããããå³å¯ã«ã¹ããã¯ãæãããã¨ã¯ãã¦ãã¾ãããï¼â»å¾åãæ´ããã¨ã主ç®çã¨ãã¦ãã¾ãï¼
- Elasticsearch
- Amazon Elasticsearch Service
- v6.7
- ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãï¼t2.small à 3ãã¼ã
- PostgreSQLï¼pg_bigm)
- Amazon EC2ä¸ã«PostgreSQLãã¤ã³ã¹ãã¼ã«ï¼RDSã§ã¯pg_bigmããµãã¼ãããã¦ããªãããï¼
- v9.6(PostgreSQL)
- v1.2(pg_bigm)
- ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ã:t2.large à 1ãã¼ã
- PostgreSQLï¼ããã©ã«ã)
- Amazon EC2ä¸ã«PostgreSQLãã¤ã³ã¹ãã¼ã«
- v9.6(PostgreSQL)
- ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ã:t2.large à 1ãã¼ã
è¨æ¸¬çµæã¨èå¯
ã¾ãã¯ããã©ã«ãï¼B-treeã¤ã³ããã¯ã¹ï¼ã®PostgreSQLã®è¨æ¸¬çµæãè¦ã¦ã¿ã¾ãããã¼ã¯ã¼ãããã®ãã¼ã¯ã¼ãã®Hit件æ°ã«ããããæä½ã§ã50ç§ä»¥ä¸ã®æéãè¦ãããã¨ããããã¾ããããã¯ããã¼ã¯ã¼ãã«ããããã·ã¼ã±ã³ã·ã£ã«ã¹ãã£ã³ï¼ãã¼ãã«ã®å ¨ã¬ã³ã¼ãã®èµ°æ»ï¼ãè¡ããããããä¸å®ã®æéãããã£ã¦ãããã¨ãè¦å ã§ãã
次ã«ãåä¸ã®ã¹ã±ã¼ã«ã®å ´åã®Elasticsearchã¨pg_bigmã®è¨æ¸¬çµæãè¦ã¦ã¿ã¾ãããã
ãã®çµæãè¦ãã¨ãåæ¹ããã¼ã¯ã¼ãã«Hitããã¬ã³ã¼ãã®æ°ã«å¿ãã¦é度ãé
ããªã£ã¦ããäºãåããã¾ããããã©ã«ãã®PostgreSQLãåºå®ã§ã·ã¼ã±ã³ã·ã£ã«ã¹ãã£ã³ã®ã³ã¹ããããã£ã¦ããã®ã«æ¯ã¹ãã¨ãé«éåãè¦è¾¼ãããã¨ãåããã¾ãããããããã¼ã¯ã¼ãHitæ°ãå¤ããªãã«ã¤ãã¦ãæ¤ç´¢é度ãããªãé
ããªã£ã¦ããããã§ããå ´åã«ãã£ã¦ã¯ãããã©ã«ãã®PostgreSQLã¨åçã®ããã©ã¼ãã³ã¹ã«ãªãã±ã¼ã¹ãããããã«ãè¦ãã¾ãã
â»ãªãããã®ã°ã©ããè¦ãã¨ãpg_bigmã®æ¹ãé«éã§ããããã«è¦ãã¾ãããããã¯æ¤è¨¼ã«ä½¿ç¨ããç°å¢ã®æ§è½å·®ã«ãããã®ã ã¨èãããã¾ããããã§ã¯è©³ç´°ãè¿°ã¹ã¾ããããElasticsearchã®ãã¼ãæ°ãå¢ãããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã®ã°ã¬ã¼ããä¸ãããã¨ã§ãæ¤ç´¢é度ãåä¸ãããã¨ã確èªã§ãã¦ãã¾ãã
å ã»ã©ã®ã¹ã±ã¼ã«ã§ã¯åããã«ããã®ã§ãããå°ãæ¡å¤§ããã°ã©ãã§è¨æ¸¬çµæãè¦ã¦ã¿ã¾ãããã ãããè¦ãã¨ãHit件æ°ãå°ãªãå ´åï¼1000件~2000件ç¨åº¦ï¼ã§ããã°ãé ãã¨ãæ°ç§ä»¥ä¸ã®é度ã§æ¤ç´¢çµæãå¾ããã¦ããããã§ãã
ã§ã¯ã次ã®ãã¼ã¿ãè¦ã¦ã¿ã¾ããããããã¯Elasticsearch,pg_bigmåæ¹ã§ããæ¤ç´¢ãã¼ã¯ã¼ãã«Hitããå é 10件ããæ¤ç´¢ããã®ã«è¦ããæéã§ãã試è¡åæ°ã¯1000åãåä½ã¯msecã§ãã
 | Elasticsearch | pg_bigm |
---|---|---|
å¹³åå¤ | 9 | 75 |
ä¸å¤®å¤ | 10 | 25 |
æå¤§å¤ | 159 | 3641 |
ãããè¦ãéããæ大å¤ããpg_bigmã§å°ãé
ãçµæãå¾ããã¦ãã¾ãããå¹³åå¤ã»ä¸å¤®å¤ãè¦ãéããããã¼ã¯ã¼ãã«Hitãã件æ°ã«ããããå
¨ä½ããå
é ã®å°æ°ã®çµæãåå¾ãããã¨ã¯ãååã«é«éãªé度ã§å®è¡ã§ãããã¨ãããã¨ãåããã¾ãã
ã¤ã¾ããããã¾ã§è¦ã¦ããçµæãããElasticsearch, pg_bigmã¯ãããã次ã®å¾åã§ããã¨è¨ããã¨èãããã¾ãã
- ãã¼ã¯ã¼ãã«Hitãã件æ°ã«ããããå ¨ä½ããå é ã®å°æ°ã®çµæãåå¾ãããã¨ã¯ãååã«é«éãªé度ã§å®è¡ã§ãã
- ãã¼ã¯ã¼ãã«Hitãã件æ°ãè¨å¤§ã§ããã®ãã¹ã¦ã®çµæãå¾ãå ´åã¯ããã©ã«ãã®PostgreSQLã¨åçããªãããã以ä¸ã®æéãè¦ãã
ä¸è¬çã«ãè¨å¤§ãªæ¤ç´¢çµæãä¸åº¦ã«åå¾ããã±ã¼ã¹ã¯å°ãªãããã¼ã¸ãã¼ãæ©è½ãç¡éã¹ã¯ãã¼ã«æ©è½ãæã£ãUIãã¶ã¤ã³ãç¨ãã¦ãé¨åçã«é 次èªã¿ã ãã¦ããã¨ããå©ç¨ã·ã¼ã³ã®æ¹ãå¤ãã¨èãããããããå¾è ã®ãã¡ãªãããé¡å¨åãããã¨ã¯ãã¾ããªãã®ã§ã¯ãªããã¨èãããã¾ãã
以ä¸ãããæ¤ç´¢é度ã¨ããç¹ã«ããã¦ã¯ãElasticsearchã¨pg_bigmã®éã«ã¯æ±ºå®çãªå·®ãç¡ããåæ¹ã¨ãå¿ è¦ååãªæ¤ç´¢æ§è½ãæããã®ã§ã¯ãªãããã¨ããçµè«ã«éãã¾ããã
ãªããä»åã¯è©³ç´°ã«è§¦ãã¾ããããRDBã§LIMIT-OFFSETã使ç¨ãã¦ãéåã®å¾åã®æ¤ç´¢çµæãå¾ãå ´åãé度ãé
ããªãã±ã¼ã¹ãããã¾ãï¼ããã¯SQLãã¥ã¼ãã³ã°ãªã©ã§å¯¾å¿ã§ãã¾ãï¼ã
ãã®ç¾è±¡ã¯Elasticsearchã§ãåæ§ã§ãããã解決ããæ段ã¨ãã¦ãElasticsearchã¯æ¬¡ã®ãããªæ©è½ãããã©ã«ãã§æã£ã¦ãã¾ãã
- Search After
- ãã¼ã¸ãã¼ã·ã§ã³ã«æé©åãããæ¤ç´¢æ¹å¼ã§ãæ¤ç´¢çµæãå é ãã¼ã¸ããé 次æ¤ç´¢ããéã«å©ç¨ã§ãã
- Scroll
- æ¤ç´¢çµæããã£ãã·ã¥ãã¦ãå¾ããé¨åçã«åå©ç¨ã§ããããã«ããä»çµã¿ãååã®ãã£ãã·ã¥ä½ææã¯æéããããã
ã¾ã¨ã
Elasticsearchã¯ãé度æ¹åãã ãã§é¸ã¶ãã®ã§ã¯ãªã
ç§ãã¡ã¯ãå½åElasticsearchãå°å ¥ãããã¨ã«ãã£ã¦æ¤ç´¢æ©è½ã®é度æ¹åãè¦è¾¼ããã®ã§ã¯ãªããã¨ãã仮説ã«åºã¥ãæ¤è¨¼ãé²ãã¦ãã¾ããããé度æ¹åã ãã主ç®çã¨ãã¦å°å ¥ã®å¤æããã¹ãã§ã¯ãªãã¨ãããã¨ãåããã¾ããã
å¾æ¥åã®æ¤ç´¢æ¹å¼ã使ãæ¹ã ãã§å¤æããã®ã§ããã°ãããããElasticsearchãå°å
¥ããå¿
è¦ã¯ãªããpg_bigmã§ãååã«é度æ¹åãè¦è¾¼ãäºãã§ãã¾ãã
Elasticsearchã«ã¯æ¬¡ã®ãããªãã¡ãªããããããå¿
ãããé¸å®æ¡ä»¶ã¨ãã¦åªä½ã¨ã¯è¨ãã¾ããã
- Elasticsearchã¨pg_bigmãæ¯è¼ããå ´åã®ãã¡ãªãã
- å¦ç¿ã³ã¹ããããã
- å¥ã®ãµã¼ãã¼ãªã½ã¼ã¹ãè¦ãã
- Elasticsearchãèé害æ§ãªã©ãèæ ®ãã¦ä½¿ç¨ããå ´åãæä½ã§ã3å°ã®ãã¼ããå¿ è¦ã¨ããRDBã¨ã¯å¥ã«ãªã½ã¼ã¹ã確ä¿ããå¿ è¦ãããã¾ãã
- æ£è¦åã§ããªãããã©ã³ã¶ã¯ã·ã§ã³ããªã
- åè¿°ã®éããElasticsearchã¯æ£è¦åãçµåãè¦æã§ãã®ã§ããã¹ã¿DBã使ç¨ããçµãè¾¼ã¿ãªã©ã®ç¨éã«ã¯åãã¦ãã¾ããã
- ã¾ãããã©ã³ã¶ã¯ã·ã§ã³ãç¡ããããACIDæ§ãæå¾ ããªãããã¾ãã¯ãå¥éä»çµã¿ãè¬ããå¿ è¦ãããã¾ãã
- ãã®ç¹ã«ããã¦ã¯ãPostgreSQLã¨ä¸ä½ã«ãªã£ã¦ããpg_bigmã®æ¹ãè¨è¨ããã¼ã¿ã®åãåããããããã¨è¨ããã§ãããã
â»pg_bigmã«ããã¤ã³ããã¯ã¹ãµã¤ãºã大ãããªãããæ´æ°å¦çã«ãªã¼ãã¼ããããå¢ãããã¨ãããã¡ãªãããããã¾ãããããã¯Elasticsearchãæ¡ç¨ããå ´åã¨æ¯è¼ãã¦ã®æ確ãªãã¡ãªããã¨ã¯è¨ããªãã¨èãã¦ãã¾ãã
é¤ ã¯é¤ å±ã§ãã
ã§ã¯ãElasticsearchã¯ã©ã®ãããªã·ã¼ã³ã§æ¡ç¨ããã¹ããªã®ãã¨ããã¨ããElasticsearchã§ããã§ããªããã¨ããéçºããã·ã¹ãã ã®è¦ä»¶ã«å«ã¾ãã¦ããå ´åã ã¨èãã¦ãã¾ããå ·ä½çã«ã¯ã
- èªç¶è¨èªã§è¨è¿°ããã大éã®ææ¸ãã¼ã¿ã«å¯¾ãã¦ãããæç« ã¨ãã¦èªç¶ãªæ¤ç´¢çµæãå¾ãã
- æ¤ç´¢ãã¼ã¯ã¼ããåºã«ããããã¾ããªæ¤ç´¢çµæãå¾ãã
- ã·ã¹ãã ã®éç¨ãç¶ç¶ããã«ã¤ãã¦è¥å¤§åãã¦ãããã¼ã¿ã«å¯¾ãã¦ãåçã«ã¯ã©ã¹ã¿æ§æãã¹ã±ã¼ãªã³ã°ããã
ã¨ãããããªã·ã¼ã³ã§ã¯ãªãã§ãããããããããç¹ã«ã¤ãã¦ã¯ãRDBã§ã¯å¯¾å¿ãé£ããå ´åãå¤ããæç« ã®æ¤ç´¢ã«ç¹åããElasticsearchãªãã§ã¯ã®æ´»ç¨ç¯å²ã§ããã¨èãã¦ãã¾ãã
ã¤ã¾ããå¾æ¥åã®æ¤ç´¢æ¹å¼ã®ã代æ¿ãã¨ãã¦ã®å½¹å²ãæå¾ ãããã¨ãééã£ã¦ããã®ã§ãããElasticsearchã®å¾æåéããã¤RDBã§ã¯ä»£æ¿ã§ããªãã¨ããã«æ¡ç¨ãããã¨ã§ãElasticsearchã®ä¾¡å¤ã享åã§ããã¨ãããã¨ã§ãã
æå¾ã«
ä»åã®æ¤è¨¼ãè¡ãã¾ã§ã¯ããã æ¼ ç¶ã¨ãElasticsearchã使ãã¨å
¨ææ¤ç´¢ãéããªãããããã¨ãã£ãç¨åº¦ã®èªèã§ããããã¾ããã§ããããæ¤è¨¼ãéãã¦ãElasticsearchã®ç¹æ§ããæ´»ç¨ç¯å²ãªã©ãç解ãããã¨ãã§ãã¾ããã
ä»å¾ãæ°è¦ãµã¼ãã¹ã®ã¢ã¼ããã¯ãã£ãæ¤è¨ãã段éã§ãElasticsearchã®ç¹æ§ããã¾ãé©ç¨ã§ãããã©ãããã¨ããç¹ããã¢ã¼ããã¯ãã£é¸å®ã®ææã«ã§ããã¨èãã¦ãã¾ãã
ä»åã®æ¤è¨¼çµæããå°ãã§ãçæ§ã®ãå½¹ã«ç«ã¦ã°å¹¸ãã§ãã
é£è¼ç®æ¬¡
- ãå ¨ææ¤ç´¢ ã Elasticsearchã¨ãã¼ã¿å¿ååææ³ã
- ãå ¨ææ¤ç´¢ã®æ¢æ± Elasticsearch(1) ã: ããã¸ã§ã¯ãæ¹éããã³Elasticsearchæ¦è¦
- 大éãã¼ã¿ãæ¤ç´¢ãããµã¼ãã¹ã§Elasticsearchã¯RDBã®ä»£æ¿åè£ã«ãªããããï¼(Elasticsearch vs pg_bigm)ã âä»èªãã§ããè¨äº
- ãã¼ã¿å¿åå 第1åï¼å¿ååãããå人æ å ±ã¨ã¯ä½ãªã®ã
- ãã¼ã¿å¿åå 第2åï¼å人æ å ±ã¯å¿ååãã¦ãæå³ããªãã®ã§ã¯ãªããï¼
- ãã¼ã¿å¿åå 第3åï¼å人æ å ±ãå¿ååããããã»ã¹
- ãã¼ã¿å¿åå 第4åï¼å¿ååã®ããã«è¡ããã¼ã¿é ç®ã®ä¸è¬åã¨ã¯
- ãã¼ã¿å¿åå 第5åï¼ãã¼ã¿å¿ååã®ææ¨
- ãã¼ã¿å¿åå 第6åï¼å®éã®å¿åå
ã¨ã³ã¸ãã¢ä¸éæ¡ç¨ãµã¤ã
ã©ã¯ã¹ã§ã¯ãã¨ã³ã¸ãã¢ã»ãã¶ã¤ãã¼ã®ä¸éæ¡ç¨ãç©æ¥µçã«è¡ã£ã¦ããã¾ãï¼
ãèå³ããã¾ãããæ¯éã確èªããé¡ããã¾ãã
https://career-recruit.rakus.co.jp/career_engineer/ã«ã¸ã¥ã¢ã«é¢è«ãç³è¾¼ã¿ãã©ã¼ã
ã©ã®è·ç¨®ã«å¿åããã°è¯ããããããªãã¨ããæ¹ã¯ãã«ã¸ã¥ã¢ã«é¢è«ãéæè¡ã£ã¦ããã¾ãã
以ä¸ãã©ã¼ã ãããç³è¾¼ã¿ãã ããã
rakus.hubspotpagebuilder.comã©ã¯ã¹Developersç»é²ãã©ã¼ã
https://career-recruit.rakus.co.jp/career_engineer/form_rakusdev/ã¤ãã³ãæ å ±
ä¼ç¤¾ã®é°å²æ°ãç¥ãããæ¹ã¯ãæ¯é±éå¬ãã¦ããã¤ãã³ãã«ãåå ãã ããï¼
âTECH PLAY
techplay.jp
âconnpass
rakus.connpass.com