Friday, January 2, 2015

elastic

  1. Introduction
    1. A general purpose R interface to Elasticsearch
    2. 아직 불안정한 상태
  2. Installation
    1. install.packages(c("rjson","plyr","httr", "devtools"))
    2. library(devtools)
    3. install_github("ropensci/elastic")
    4. library(elastic)
  3. Example
    1. es_connect("http://211.49.227.177")
      uri:       http://211.49.227.177 
      port:      9200 
      username:  NULL 
      password:  NULL 
      api key:   NULL 
      elasticsearch details:   
            status:                  200 
            name:                    es01 
            Elasticsearch version:   1.3.2 
            ES version timestamp:    2014-08-13T14:29:30Z 
            lucene version:          4.9
    2. myList <- es_search(index = "mysql*")
      http://211.49.227.177:9200/mysql*/_search?=
      matches -> 175
      score -> 1
    3. head(myList$hits$hits, 1)
      [[1]]
      [[1]]$`_index`
      [1] "mysql-2014.08"
      [[1]]$`_type`
      [1] "mysql-slow"
      [[1]]$`_id`
      [1] "o5Myqc1qTCGM4FA6Mqjf8g"
      [[1]]$`_score`
      [1] 1
      [[1]]$`_source`
      [[1]]$`_source`$message
      [1] "# Query_time: 12.990768  Lock_time: 0.000107 Rows_sent: 1063  Rows_examined: 2751606\nSET timestamp=1408978814;\nSELECT *\nFROM test.recruit\nWHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\n\n\tINTO OUTFILE 'SYNC_recruit_data.sql' \n\tFIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"'\n\tLINES TERMINATED BY '\\n';"
      [[1]]$`_source`$`@version`
      [1] "1"
      [[1]]$`_source`$`@timestamp`
      [1] "2014-08-25T15:00:14.000Z"
      [[1]]$`_source`$type
      [1] "mysql-slow"
      [[1]]$`_source`$host
      [1] "vm00037-1.pm0132.z1.visioncloud.co.kr"
      [[1]]$`_source`$path
      [1] "/DBLog/dbmaster-slow.log"
      [[1]]$`_source`$query_time
      [1] 12.99077
      [[1]]$`_source`$lock_time
      [1] 0.000107
      [[1]]$`_source`$rows_sent
      [1] 1063
      [[1]]$`_source`$rows_examined
      [1] 2751606
      [[1]]$`_source`$tags
      [1] "multiline"
      [[1]]$`_source`$query
      [1] "SELECT *"                                               "FROM test.recruit"                               
      [3] "WHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)" "\tINTO OUTFILE 'SYNC_recruit_data.sql' "               
      [5] "\tFIELDS TERMINATED BY ',' "                            "\tOPTIONALLY ENCLOSED BY '\"'"                         
      [7] "\tLINES TERMINATED BY '\\n';"
    4. myList <- es_get(index = "mysql-2014.08", type = "mysql-slow", id = "o5Myqc1qTCGM4FA6Mqjf8g")
      http://211.49.227.177:9200/mysql-2014.08/mysql-slow/o5Myqc1qTCGM4FA6Mqjf8g?=
    5. myList
      $`_index`
      [1] "mysql-2014.08"
      $`_type`
      [1] "mysql-slow"
      $`_id`
      [1] "o5Myqc1qTCGM4FA6Mqjf8g"
      $`_version`
      [1] 1
      $found
      [1] TRUE
      $`_source`
      $`_source`$message
      [1] "# Query_time: 12.990768  Lock_time: 0.000107 Rows_sent: 1063  Rows_examined: 2751606\nSET timestamp=1408978814;\nSELECT *\nFROM test.recruit\nWHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\n\n\tINTO OUTFILE 'SYNC_recruit_data.sql' \n\tFIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"'\n\tLINES TERMINATED BY '\\n';"
      $`_source`$`@version`
      [1] "1"
      $`_source`$`@timestamp`
      [1] "2014-08-25T15:00:14.000Z"
      $`_source`$type
      [1] "mysql-slow"
      $`_source`$host
      [1] "vm00037-1.pm0132.z1.visioncloud.co.kr"
      $`_source`$path
      [1] "/DBLog/dbmaster-slow.log"
      $`_source`$query_time
      [1] 12.99077
      $`_source`$lock_time
      [1] 0.000107
      $`_source`$rows_sent
      [1] 1063
      $`_source`$rows_examined
      [1] 2751606
      $`_source`$tags
      [1] "multiline"
      $`_source`$query
      [1] "SELECT *"                                               "FROM test.recruit"                               
      [3] "WHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)" "\tINTO OUTFILE 'SYNC_recruit_data.sql' "               
      [5] "\tFIELDS TERMINATED BY ',' "                            "\tOPTIONALLY ENCLOSED BY '\"'"                         
      [7] "\tLINES TERMINATED BY '\\n';"
    6. myList <- es_mget(index = "mysql-2014.08", type = "mysql-slow", id = c("o5Myqc1qTCGM4FA6Mqjf8g", "k7g8SIwzQDqj0d0ZyuTcjQ"))
      http://211.49.227.177:9200/mysql-2014.08/mysql-slow/_mget?=
      Warning message:
      multipart is deprecated, please use encode argument instead 
    7. myList
      $docs
      $docs[[1]]
      $docs[[1]]$`_index`
      [1] "mysql-2014.08"
      $docs[[1]]$`_type`
      [1] "mysql-slow"
      $docs[[1]]$`_id`
      [1] "o5Myqc1qTCGM4FA6Mqjf8g"
      $docs[[1]]$`_version`
      [1] 1
      $docs[[1]]$found
      [1] TRUE
      $docs[[1]]$`_source`
      $docs[[1]]$`_source`$message
      [1] "# Query_time: 12.990768  Lock_time: 0.000107 Rows_sent: 1063  Rows_examined: 2751606\nSET timestamp=1408978814;\nSELECT *\nFROM test.recruit\nWHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\n\n\tINTO OUTFILE 'SYNC_recruit_data.sql' \n\tFIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"'\n\tLINES TERMINATED BY '\\n';"
      $docs[[1]]$`_source`$`@version`
      [1] "1"
      $docs[[1]]$`_source`$`@timestamp`
      [1] "2014-08-25T15:00:14.000Z"
      $docs[[1]]$`_source`$type
      [1] "mysql-slow"
      $docs[[1]]$`_source`$host
      [1] "vm00037-1.pm0132.z1.visioncloud.co.kr"
      $docs[[1]]$`_source`$path
      [1] "/DBLog/dbmaster-slow.log"
      $docs[[1]]$`_source`$query_time
      [1] 12.99077
      $docs[[1]]$`_source`$lock_time
      [1] 0.000107
      $docs[[1]]$`_source`$rows_sent
      [1] 1063
      $docs[[1]]$`_source`$rows_examined
      [1] 2751606
      $docs[[1]]$`_source`$tags
      [1] "multiline"
      $docs[[1]]$`_source`$query
      [1] "SELECT *"                                               "FROM test.recruit"                               
      [3] "WHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)" "\tINTO OUTFILE 'SYNC_recruit_data.sql' "               
      [5] "\tFIELDS TERMINATED BY ',' "                            "\tOPTIONALLY ENCLOSED BY '\"'"                         
      [7] "\tLINES TERMINATED BY '\\n';"                          
      $docs[[2]]
      $docs[[2]]$`_index`
      [1] "mysql-2014.08"
      $docs[[2]]$`_type`
      [1] "mysql-slow"
      $docs[[2]]$`_id`
      [1] "k7g8SIwzQDqj0d0ZyuTcjQ"
      $docs[[2]]$`_version`
      [1] 1
      $docs[[2]]$found
      [1] TRUE
      $docs[[2]]$`_source`
      $docs[[2]]$`_source`$message
      [1] "# Query_time: 12.592568  Lock_time: 0.000116 Rows_sent: 1063  Rows_examined: 2751606\nSET timestamp=1408980253;\nSELECT *\nFROM test.recruit\nWHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\n\n\tINTO OUTFILE 'SYNC_recruit_data.sql' \n\tFIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"'\n\tLINES TERMINATED BY '\\n';"
      $docs[[2]]$`_source`$`@version`
      [1] "1"
      $docs[[2]]$`_source`$`@timestamp`
      [1] "2014-08-25T15:24:13.000Z"
      $docs[[2]]$`_source`$type
      [1] "mysql-slow"
      $docs[[2]]$`_source`$host
      [1] "vm00037-1.pm0132.z1.visioncloud.co.kr"
      $docs[[2]]$`_source`$path
      [1] "/DBLog/dbmaster-slow.log"
      $docs[[2]]$`_source`$query_time
      [1] 12.59257
      $docs[[2]]$`_source`$lock_time
      [1] 0.000116
      $docs[[2]]$`_source`$rows_sent
      [1] 1063
      $docs[[2]]$`_source`$rows_examined
      [1] 2751606
      $docs[[2]]$`_source`$tags
      [1] "multiline"
      $docs[[2]]$`_source`$query
      [1] "SELECT *"                                               "FROM test.recruit"                               
      [3] "WHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)" "\tINTO OUTFILE 'SYNC_recruit_data.sql' "               
      [5] "\tFIELDS TERMINATED BY ',' "                            "\tOPTIONALLY ENCLOSED BY '\"'"                         
      [7] "\tLINES TERMINATED BY '\\n';"
    8. myList <- es_get(index = "mysql-2014.08", type = "mysql-slow", id = "o5Myqc1qTCGM4FA6Mqjf8g", raw = T)
      http://211.49.227.177:9200/mysql-2014.08/mysql-slow/o5Myqc1qTCGM4FA6Mqjf8g?=
    9. myList
      [1] "{\"_index\":\"mysql-2014.08\",\"_type\":\"mysql-slow\",\"_id\":\"o5Myqc1qTCGM4FA6Mqjf8g\",\"_version\":1,\"found\":true,\"_source\":{\"message\":\"# Query_time: 12.990768  Lock_time: 0.000107 Rows_sent: 1063  Rows_examined: 2751606\\nSET timestamp=1408978814;\\nSELECT *\\nFROM test.recruit\\nWHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\\n\\n\\tINTO OUTFILE 'SYNC_recruit_data.sql' \\n\\tFIELDS TERMINATED BY ',' \\n\\tOPTIONALLY ENCLOSED BY '\\\"'\\n\\tLINES TERMINATED BY '\\\\n';\",\"@version\":\"1\",\"@timestamp\":\"2014-08-25T15:00:14.000Z\",\"type\":\"mysql-slow\",\"host\":\"vm00037-1.pm0132.z1.visioncloud.co.kr\",\"path\":\"/DBLog/dbmaster-slow.log\",\"query_time\":12.990768,\"lock_time\":0.000107,\"rows_sent\":1063,\"rows_examined\":2751606.0,\"tags\":[\"multiline\"],\"query\":[\"SELECT *\",\"FROM test.recruit\",\"WHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\",\"\\tINTO OUTFILE 'SYNC_recruit_data.sql' \",\"\\tFIELDS TERMINATED BY ',' \",\"\\tOPTIONALLY ENCLOSED BY '\\\"'\",\"\\tLINES TERMINATED BY '\\\\n';\"]}}"
      attr(,"class")
      [1] "elastic_get"
    10. es_parse(myList)
      $`_index`
      [1] "mysql-2014.08"
      $`_type`
      [1] "mysql-slow"
      $`_id`
      [1] "o5Myqc1qTCGM4FA6Mqjf8g"
      $`_version`
      [1] 1
      $found
      [1] TRUE
      $`_source`
      $`_source`$message
      [1] "# Query_time: 12.990768  Lock_time: 0.000107 Rows_sent: 1063  Rows_examined: 2751606\nSET timestamp=1408978814;\nSELECT *\nFROM test.recruit\nWHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)\n\n\tINTO OUTFILE 'SYNC_recruit_data.sql' \n\tFIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"'\n\tLINES TERMINATED BY '\\n';"
      $`_source`$`@version`
      [1] "1"
      $`_source`$`@timestamp`
      [1] "2014-08-25T15:00:14.000Z"
      $`_source`$type
      [1] "mysql-slow"
      $`_source`$host
      [1] "vm00037-1.pm0132.z1.visioncloud.co.kr"
      $`_source`$path
      [1] "/DBLog/dbmaster-slow.log"
      $`_source`$query_time
      [1] 12.99077
      $`_source`$lock_time
      [1] 0.000107
      $`_source`$rows_sent
      [1] 1063
      $`_source`$rows_examined
      [1] 2751606
      $`_source`$tags
      [1] "multiline"
      $`_source`$query
      [1] "SELECT *"                                               "FROM test.recruit"                               
      [3] "WHERE edit_dt >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)" "\tINTO OUTFILE 'SYNC_recruit_data.sql' "               
      [5] "\tFIELDS TERMINATED BY ',' "                            "\tOPTIONALLY ENCLOSED BY '\"'"                         
      [7] "\tLINES TERMINATED BY '\\n';" 


  4. Reference

    https://github.com/ropensci/elastic

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.