http://blog.csdn.net/lgnlgn/article/details/8053626 elasticsearch学习入门

input {stdin{}}
filter {
grok {
match => {
"message" => ".*(?<json_body>\{.*\}).*"
}
}
json {
source => "json_body"
}

}

************jdbc-in********************

input {
jdbc {
jdbc_driver_library => "/home/app/logstash/vendor/jar/jdbc/mysql-connector-java-5.1.36-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://12.0.1.28:3306/ucampus_dev?characterEncoding=utf8"
jdbc_user => "user"
jdbc_password => "Kn!0748j"
statement => "SELECT * FROM sys_online_history limit 0,1"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
schedule => "* * * * *"
}
}

filter {
json {
source => "message"
remove_field => ["message"]
}
}

output {
stdout {
codec => rubydebug
}
}

************jdbc-in********************

检查ES集群状态:

curl 54.223.139.77:9200/_cat/health?v

  检查ES节点状态:

curl 54.223.139.77:9200/_cat/nodes?v

  查询所有的索引:

curl 54.223.139.77:9200/_cat/indices?v

curl -XPUT 'http://localhost:9200/twitter/'

$ curl -XPUT 'http://localhost:9200/twitter/'
-d '

index :

number_of_shards : 3

number_of_replicas : 2

'

上面第二个curl例子展示了如何创建一个名字叫 twitter 的索引,并且使用 YAML
格式为其指定设置项。在这个例子中,我们为该索引配置了三个切片和两个副本。索引设置项也可以通过 JSON 格式指定:

$ curl -XPUT 'http://localhost:9200/twitter/'
-d '{

"settings" : {

"index" : {

"number_of_shards" : 3,

"number_of_replicas" : 2

}

}

}'

或者简化为

$ curl -XPUT 'http://localhost:9200/twitter/'
-d '{

"settings" : {

"number_of_shards" : 3,

"number_of_replicas" : 2

}

}'

curl -XPOST localhost:9200/test -d '{

"settings" : {

"number_of_shards" : 1

},

"mappings" : {

"type1" : {

"_source" : { "enabled" : false },

"properties" : {

"field1" : { "type" : "string", "index" :
"not_analyzed" }

}

}

}

}'


删除索引

curl -XDELETE localhost:9200/索引名字

  查询索引:

curl -XGET localhost:9200/索引名字/类型名字/id

ES 使用bulk 添加数据

  动态映射无法添加数据,不要担心!可以使用bulk命令,添加json文件内的数据。

  1 定义json数据文件:

{"index":{"_index":"aaa123","_id":1}}
{"name":"xingoo","age":25}
{"index":{"_index":"aaa123","_id":2}}
{"name":"test111","age":31}
{"index":{"_index":"aaa123","_id":3}}
{"name":"test222","age":42}
{"index":{"_index":"aaa123","_id":4}}
{"name":"test333","age":13}

  注意的是,json文件名称随意指定,第一行定义了索引和一些常用字段:

  _index定义了索引的名称,如果没有指定需要在curl命令中添加索引名称字段

  _type定义了索引的类型,如果没有指定需要在curl命令中添加索引类型字段

  _id定义了该行数据的id,如果没有指定,会随机生成一串数字。

  2 执行命令

  进入到json文件所在的目录,执行命令

curl localhost:9200/索引名称/索引类型/_bulk?pretty --data-binary @data.json

  注意的是:

  如果json文件中定义了_index和_type,那么这里可以不写变成(即便写了也会按照json文件中的生成)

curl localhost:9200/_bulk?pretty --data-binary @data.json
field 换 type
首先创建一个新的索引
curl -XPUT localhost:8305/store_v2 -d '
{
    "settings" : {
        "number_of_shards" : 20
    },
    "mappings" : {
      "client" : {
        "properties" : {
          "ip" : {
            "type" "string"
          },
          "cost" : {
            "type" "long"
          },
}
 
 ====create index mapping  curl -XPUT 54.223.139.77:9200/store_v2 --data-binary @data1.json python用起来比较熟,所以我就直接选 pyes了,装了一大堆破依赖库之后,终于可以run起来了 import pyes conn = pyes.es.ES("http://10.xx.xx.xx:8305/") search = pyes.query.MatchAllQuery().search(bulk_read=1000) hits = conn.search(search, 'store_v1', 'client', scan=True, scroll="30m", model=lambda _,hit: hit) for hit in hits:      #print hit      conn.index(hit['_source'], 'store_v2', 'client', hit['_id'], bulk=True) conn.flush()   花了大概一个多小时,新的索引基本和老索引数据一致了,对于线上完成瞬间的增量,这里没心思关注了,数据准确性要求没那么高,得过且过。 接下来修改alias别名的指向(如果你之前没有用alias来改mapping,纳尼就等着哭吧) curl -XPOST localhost:8305/_aliases -d ' {     "actions": [         { "remove": {             "alias": "store",             "index": "store_v1"         }},         { "add": {             "alias": "store",             "index": "store_v2"         }}     ] }

等新索引的数据已经追上时

将老的索引删掉

1
curl -XDELETE localhost:8303/store_v1

最新文章

  1. logback配置详解1
  2. [深入Python]sys.modules
  3. JS时间
  4. jQuery - 中文輸入法與KeyDown/KeyPress事件
  5. Oracle DBA 的常用Unix参考手册(二)
  6. 在VS上配置OpenCV
  7. H264 NAL解析
  8. 51 nod 1628 非波那契树
  9. 两个arduino的通信
  10. [python] 2、python使用pyaudio进行录音,及其在python虚拟环境virtualenv中安装遇到的问题
  11. 学号 20175212 《Java程序设计》第3周学习总结
  12. 自然周与自然月的Hive统计SQL
  13. Python多进程并发操作进程池Pool
  14. 剑指offer:二叉树的深度
  15. cocos2d-x中使用CCOrbitCamera做水平翻转
  16. IntelliJ IDEA 2017版 导入maven项目需要的包
  17. Sqlserver学习研究
  18. 从JavaScript 数组去重看兼容性有关问题,及性能优化(摘自玉伯博客)
  19. NFS介绍
  20. better1【模式】Module模式

热门文章

  1. CXF学习笔记 之 “注解”
  2. 【高并发简单解决方案】redis缓存队列+mysql 批量入库+php离线整合
  3. FreeRTOS基础知识
  4. 80X86寄存器介绍
  5. CSS学习笔记(4)--选择器(w3school)
  6. mysql 位运算
  7. [misc]printf/fprintf/sprintf/snprintf函数
  8. EMC、Pure和NetApp推新品,NAS闪存场景在哪里
  9. 服务器的svnserver修改密码
  10. 第二百七十一节,Tornado框架-CSRF防止跨站post请求伪造