设为首页 收藏本站
查看: 854|回复: 0

[经验分享] 54 搜索引擎及Lucene基础、elasticsearch使用基础、ES使用详解、ES查询及Logstash入门

[复制链接]

尚未签到

发表于 2019-1-29 12:39:15 | 显示全部楼层 |阅读模式
  01搜索引擎及Lucene基础
  

  02elasticsearch使用基础
  配置环境
  node1:192.168.1.131CentOS Linux release 7.2
  node2:192.168.1.132CentOS Linux release 7.2
  node3:192.168.1.133CentOS Linux release 7.2
  

  [root@node1 ~]# vim /etc/profile.d/java.sh
  export JAVA_HOME=/usr
  [root@node1 ~]# yum install java-1.7.0-openjdk-devel.x86_64  -y
  [root@node1 ~]# ls elasticsearch-1.7.2.noarch.rpm
  elasticsearch-1.7.2.noarch.rpm
  [root@node1 ~]# yum install elasticsearch-1.7.2.noarch.rpm -y
  [root@node1 ~]# cd /etc/elasticsearch/
  [root@node1 elasticsearch]# ls
  elasticsearch.yml  logging.yml
  [root@node1 elasticsearch]# vim elasticsearch.yml
  修改
  #cluster.name: elasticsearch
  
  cluster.name: myes
  修改
  #node.name: "Franz Kafka"
  
  node.name: "node1"
  [root@node1 elasticsearch]# systemctl daemon-reload
  [root@node1 elasticsearch]# systemctl start elasticsearch.service
  [root@node1 elasticsearch]# scp /etc/profile.d/java.sh node2:/etc/profile.d/
  [root@node1 elasticsearch]# scp /etc/profile.d/java.sh node3:/etc/profile.d/
  [root@node1 ~]# scp elasticsearch-1.7.2.noarch.rpm node2:/root
  [root@node1 ~]# scp elasticsearch-1.7.2.noarch.rpm node3:/root
  

  [root@node2 ~]# yum makecache
  [root@node2 ~]# yum install java-1.7.0-openjdk-devel.x86_64 -y
  [root@node2 ~]# yum -y install elasticsearch-1.7.2.noarch.rpm
  [root@node2 ~]# vim /etc/elasticsearch/elasticsearch.yml
  修改
  #cluster.name: elasticsearch
  
  cluster.name: myes
  修改
  #node.name: "Franz Kafka"
  
  node.name: "node2"
  [root@node2 ~]# systemctl daemon-reload
  [root@node2 ~]# systemctl start elasticsearch.service   
  [root@node2 ~]# tcpdump -i eno16777736 -nn tcp port 9300
  tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
  listening on eno16777736, link-type EN10MB (Ethernet), capture size 65535 bytes
  10:56:33.167425 IP 192.168.1.131.52903 > 192.168.1.132.9300: Flags [P.], seq 1407746623:1407746775, ack 4084412475, win 229, options [nop,nop,TS val 45551409 ecr 45077643], length 152
  10:56:33.168800 IP 192.168.1.132.9300 > 192.168.1.131.52903: Flags [P.], seq 1:21, ack 152, win 1432, options [nop,nop,TS val 45078647 ecr 45551409], length 20
  10:56:33.169334 IP 192.168.1.132.33552 > 192.168.1.131.9300: Flags [P.], seq 2860848390:2860848499, ack 2667737508, win 229, options [nop,nop,TS val 45078648 ecr 45550408], length 109
  10:56:33.169468 IP 192.168.1.131.52903 > 192.168.1.132.9300: Flags [.], ack 21, win 229, options [nop,nop,TS val 45551411 ecr 45078647], length 0
  10:56:33.170588 IP 192.168.1.131.9300 > 192.168.1.132.33552: Flags [P.], seq 1:21, ack 109, win 227, options [nop,nop,TS val 45551413 ecr 45078648], length 20
  10:56:33.170632 IP 192.168.1.132.33552 > 192.168.1.131.9300: Flags [.], ack 21, win 229, options [nop,nop,TS val 45078649 ecr 45551413], length 0
  ^C
  6 packets captured
  6 packets received by filter
  0 packets dropped by kernel
  

  [root@node3 ~]# yum makecache
  [root@node3 ~]# yum install java-1.7.0-openjdk-devel.x86_64 -y
  [root@node3 ~]# yum -y install elasticsearch-1.7.2.noarch.rpm
  [root@node3 ~]# vim /etc/elasticsearch/elasticsearch.yml
  修改
  #cluster.name: elasticsearch
  
  cluster.name: myes
  修改
  #node.name: "Franz Kafka"
  
  node.name: "node3"
  [root@node3 elasticsearch]# systemctl daemon-reload
  [root@node3 elasticsearch]# systemctl start elasticsearch.service
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.131:9200/?preey'
  {
    "status" : 200,
    "name" : "node1",
    "cluster_name" : "myes",
    "version" : {
      "number" : "1.7.2",
      "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
      "build_timestamp" : "2015-09-14T09:49:53Z",
      "build_snapshot" : false,
      "lucene_version" : "4.10.4"
    },
    "tagline" : "You Know, for Search"
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.132:9200/?preey'
  {
    "status" : 200,
    "name" : "node2",
    "cluster_name" : "myes",
    "version" : {
      "number" : "1.7.2",
      "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
      "build_timestamp" : "2015-09-14T09:49:53Z",
      "build_snapshot" : false,
      "lucene_version" : "4.10.4"
    },
    "tagline" : "You Know, for Search"
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/?preey'
  {
    "status" : 200,
    "name" : "node3",
    "cluster_name" : "myes",
    "version" : {
      "number" : "1.7.2",
      "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
      "build_timestamp" : "2015-09-14T09:49:53Z",
      "build_snapshot" : false,
      "lucene_version" : "4.10.4"
    },
    "tagline" : "You Know, for Search"
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/'
  =^.^=
  /_cat/allocation
  /_cat/shards
  /_cat/shards/{index}
  /_cat/master
  /_cat/nodes
  /_cat/indices
  /_cat/indices/{index}
  /_cat/segments
  /_cat/segments/{index}
  /_cat/count
  /_cat/count/{index}
  /_cat/recovery
  /_cat/recovery/{index}
  /_cat/health
  /_cat/pending_tasks
  /_cat/aliases
  /_cat/aliases/{alias}
  /_cat/thread_pool
  /_cat/plugins
  /_cat/fielddata
  /_cat/fielddata/{fields}
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/nodes'
  node2 192.168.1.132 5 18 0.00 d m node2
  node1 192.168.1.131 6 18 0.08 d * node1
  node3 192.168.1.133 4 18 0.01 d m node3
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/nodes?v'
  host  ip            heap.percent ram.percent load node.role master name  
  node2 192.168.1.132            5          19 0.00 d         m      node2
  node1 192.168.1.131            6          18 0.03 d         *      node1
  node3 192.168.1.133            4          18 0.00 d         m      node3
  

  #显示帮助
  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/nodes?help'
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/nodes?h=name,ip,port,uptime,heap.current'
  node2 192.168.1.132 9300 38.1m 53.8mb
  node1 192.168.1.131 9300 53.1m 64.8mb
  node3 192.168.1.133 9300 30.9m 50.5mb
  

  #查看主节点
  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/master'  hdbLm-k-Q4eY9RxeMvAJDw node1 192.168.1.131 node1
  #详细格式
  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/master?v'
  id                     host  ip            node  
  hdbLm-k-Q4eY9RxeMvAJDw node1 192.168.1.131 node1
  

  #显示健康状态
  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/health'  1483328079 11:34:39 myes green 3 3 0 0 0 0 0 0
  #详细格式
  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/health?v'epoch      timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks
  1483328108 11:35:08  myes    green           3         3      0   0    0    0        0             0
  

  

  03ES使用详解
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/health?level=cluster'
  {"cluster_name":"myes","status":"green","timed_out":false,"number_of_nodes":3,"number_of_data_nodes":3,"active_primary_shards":0,"active_shards":0,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":0,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0}
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/health?level=indicies&pretty'
  {
    "cluster_name" : "myes",
    "status" : "green",
    "timed_out" : false,
    "number_of_nodes" : 3,
    "number_of_data_nodes" : 3,
    "active_primary_shards" : 0,
    "active_shards" : 0,
    "relocating_shards" : 0,
    "initializing_shards" : 0,
    "unassigned_shards" : 0,
    "delayed_unassigned_shards" : 0,
    "number_of_pending_tasks" : 0,
    "number_of_in_flight_fetch" : 0
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/state/version'{"cluster_name":"myes","version":4}
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/state/version?pretty'{
    "cluster_name" : "myes",
    "version" : 4
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/state/master_node?pretty'
  {
    "cluster_name" : "myes",
    "master_node" : "hdbLm-k-Q4eY9RxeMvAJDw"
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/state/nodes?pretty'
  {
    "cluster_name" : "myes",
    "nodes" : {
      "Jrbz7cRSQlaBH3zHw5x__g" : {
        "name" : "node2",
        "transport_address" : "inet[/192.168.1.132:9300]",
        "attributes" : { }
      },
      "hdbLm-k-Q4eY9RxeMvAJDw" : {
        "name" : "node1",
        "transport_address" : "inet[/192.168.1.131:9300]",
        "attributes" : { }
      },
      "A7dqV-odSDOdPgscxEpWWg" : {
        "name" : "node3",
        "transport_address" : "inet[/192.168.1.133:9300]",
        "attributes" : { }
      }
    }
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cluster/state/nodes?pretty'{
    "cluster_name" : "myes",
    "nodes" : {
      "Jrbz7cRSQlaBH3zHw5x__g" : {
        "name" : "node2",
        "transport_address" : "inet[/192.168.1.132:9300]",
        "attributes" : { }
      },
      "hdbLm-k-Q4eY9RxeMvAJDw" : {
        "name" : "node1",
        "transport_address" : "inet[/192.168.1.131:9300]",
        "attributes" : { }
      },
      "A7dqV-odSDOdPgscxEpWWg" : {
        "name" : "node3",
        "transport_address" : "inet[/192.168.1.133:9300]",
        "attributes" : { }
      }
    }
  }
  

  [root@node3 ~]# curl -X GET 'http://192.168.1.132:9200/_cluster/stats?pretty'
  {
    "timestamp" : 1483330621606,
    "cluster_name" : "myes",
    "status" : "green",
    "indices" : {
      "count" : 0,
      "shards" : { },
      "docs" : {
        "count" : 0,
        "deleted" : 0
      },
      "store" : {
        "size_in_bytes" : 0,
        "throttle_time_in_millis" : 0
      },
      "fielddata" : {
        "memory_size_in_bytes" : 0,
        "evictions" : 0
      },
      "filter_cache" : {
        "memory_size_in_bytes" : 0,
        "evictions" : 0
      },
      "id_cache" : {
        "memory_size_in_bytes" : 0
      },
      "completion" : {
        "size_in_bytes" : 0
      },
      "segments" : {
        "count" : 0,
        "memory_in_bytes" : 0,
        "index_writer_memory_in_bytes" : 0,
        "index_writer_max_memory_in_bytes" : 0,
        "version_map_memory_in_bytes" : 0,
        "fixed_bit_set_memory_in_bytes" : 0
      },
      "percolate" : {
        "total" : 0,
        "time_in_millis" : 0,
        "current" : 0,
        "memory_size_in_bytes" : -1,
        "memory_size" : "-1b",
        "queries" : 0
      }
    },
    "nodes" : {
      "count" : {
        "total" : 3,
        "master_only" : 0,
        "data_only" : 0,
        "master_data" : 3,
        "client" : 0
      },
      "versions" : [ "1.7.2" ],
      "os" : {
        "available_processors" : 12,
        "mem" : {
          "total_in_bytes" : 11903852544
        },
        "cpu" : [ {
          "vendor" : "Intel",
          "model" : "Xeon",
          "mhz" : 2600,
          "total_cores" : 4,
          "total_sockets" : 2,
          "cores_per_socket" : 2,
          "cache_size_in_bytes" : 15360,
          "count" : 3
        } ]
      },
      "process" : {
        "cpu" : {
          "percent" : 3
        },
        "open_file_descriptors" : {
          "min" : 203,
          "max" : 204,
          "avg" : 203
        }
      },
      "jvm" : {
        "max_uptime_in_millis" : 5914721,
        "versions" : [ {
          "version" : "1.8.0_101",
          "vm_name" : "OpenJDK 64-Bit Server VM",
          "vm_version" : "25.101-b13",
          "vm_vendor" : "Oracle Corporation",
          "count" : 3
        } ],
        "mem" : {
          "heap_used_in_bytes" : 183060568,
          "heap_max_in_bytes" : 3116630016
        },
        "threads" : 129
      },
      "fs" : {
        "total_in_bytes" : 64393052160,
        "free_in_bytes" : 51360722944,
        "available_in_bytes" : 51360722944,
        "disk_reads" : 72943,
        "disk_writes" : 30331,
        "disk_io_op" : 103274,
        "disk_read_size_in_bytes" : 1429777920,
        "disk_write_size_in_bytes" : 1544204288,
        "disk_io_size_in_bytes" : 2973982208
      },
      "plugins" : [ ]
    }
  }
  

  [root@node3 ~]# /usr/share/elasticsearch/bin/plugin -h
  Usage:
      -u, --url     [plugin location]   : Set exact URL to download the plugin from
      -i, --install [plugin name]       : Downloads and installs listed plugins

  •       -t, --timeout [duration]          : Timeout setting: 30s, 1m, 1h... (infinite by default)
          -r, --remove  [plugin name]       : Removes listed plugins
          -l, --list                        : List installed plugins
          -v, --verbose                     : Prints verbose messages
          -s, --silent                      : Run in silent mode
          -h, --help                        : Prints this help message
      

      
  • Plugin name could be:
           elasticsearch/plugin/version for official elasticsearch plugins (download from download.elasticsearch.org)
           groupId/artifactId/version   for community plugins (download from maven central or oss sonatype)
           username/repository          for site plugins (download from github master)
      
      [root@node3 ~]# /usr/share/elasticsearch/bin/plugin -i marvel -u ftp://192.168.56.2/pub/Sources/7.x86_64/elk/plugins/marvel-latest.zip
      

      [root@node1 ~]# /usr/share/elasticsearch/bin/plugin -i bigdesk -u file:///root/bigdesk-latest.zip -> Installing bigdesk...
      Trying file:/root/bigdesk-latest.zip...
      Downloading ....DONE
      Installed bigdesk into /usr/share/elasticsearch/plugins/bigdesk
      Identified as a _site plugin, moving to _site structure ...
      

      [root@node1 ~]# /usr/share/elasticsearch/bin/plugin -l
      Installed plugins:
          - bigdesk
      

      [root@node1 ~]# /usr/share/elasticsearch/bin/plugin -i head -u file:///root/elasticsearch-head-latest.zip -> Installing head...
      Trying file:/root/elasticsearch-head-latest.zip...
      Downloading .........DONE
      Installed head into /usr/share/elasticsearch/plugins/head
      

      [root@node1 ~]# /usr/share/elasticsearch/bin/plugin -i kopf -u file:///root/elasticsearch-kopf-master.zip -> Installing kopf...
      Trying file:/root/elasticsearch-kopf-master.zip...
      Downloading ....................DONE
      Installed kopf into /usr/share/elasticsearch/plugins/kopf
      

      [root@node1 ~]# /usr/share/elasticsearch/bin/plugin -i marvel -u file:///root/marvel-latest.zip -> Installing marvel...
      Trying file:/root/marvel-latest.zip...
      Downloading ....................DONE
      Installed marvel into /usr/share/elasticsearch/plugins/marvel
      

      [root@node1 ~]# /usr/share/elasticsearch/bin/plugin -l
      Installed plugins:
          - bigdesk
          - head
          - kopf
          - marvel
      [root@node1 ~]# systemctl restart elasticsearch.service
      http://192.168.1.131:9200/_plugin/marvel/kibana/#/dashboard/file/marvel.overview.json
      

      [root@node3 ~]# curl -XGET 'http://192.168.1.133:9200/_cat/indices?' //192.168.56.2/pub/Sources/7.x86_64/elk/plugins/marvel-latest.zip
      green open .marvel-2017.01.02 1 1 57 0 861.4kb 512.2kb
      green open .marvel-ki
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/1?pretty' -d'
      > {
      >   "first_name": "Jing",
      >   "last_name": "Guo",
      >   "gender" : "Male",
      >   "courses" : "Xianglong Shiba Zhang"
      > }'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "1",
        "_version" : 1,
        "created" : true
      }
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/2?pretty' -d '
      > {
      >   "first_name" : "Rong",
      >   "last_name" : "Huang",
      >   "gender" : "Female",
      >   "age" : 23,
      >   "courses" : "Luoying Shenjian"
      > }'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "_version" : 1,
        "created" : true
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/class1/1?pretty'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "1",
        "_version" : 1,
        "found" : true,
        "_source":
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/class1/2?pretty'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "_version" : 1,
        "found" : true,
        "_source":
      {
        "first_name" : "Rong",
        "last_name" : "Huang",
        "gender" : "Female",
        "age" : 23,
        "courses" : "Luoying Shenjian"
      }
      }
      

      [root@node3 ~]# curl -XPOST 'localhost:9200/students/class1/2/_update?pretty' -d '
      {
        "doc" : { "age" : 22 }
      }'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "_version" : 2
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/class1/2?pretty'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "_version" : 2,
        "found" : true,
        "_source":{"first_name":"Rong","last_name":"Huang","gender":"Female","age":22,"courses":"Luoying Shenjian"}
      }
      

      [root@node3 ~]# curl -XDELETE 'localhost:9200/students/class1/2'   
      {"found":true,"_index":"students","_type":"class1","_id":"2","_version":3}
      [root@node3 ~]# curl -XGET 'localhost:9200/students/class1/2?pretty'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "found" : false
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/_cat/indices?v'
      health status index              pri rep docs.count docs.deleted store.size pri.store.size
      green  open   .marvel-2017.01.02   1   1        273            0      3.7mb          1.8mb
      green  open   students             5   1          1            0      7.3kb          3.6kb
      green  open   .marvel-kibana       1   1          1            0      6.5kb          3.2kb
      

      [root@node3 ~]# curl -XDELETE 'localhost:9200/students'
      {"acknowledged":true}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/_cat/indices?v'
      health status index              pri rep docs.count docs.deleted store.size pri.store.size
      green  open   .marvel-2017.01.02   1   1        319            0      4.2mb          2.1mb
      green  open   .marvel-kibana       1   1          1            0      6.5kb          3.2kb
      

      

      [root@node3 ~]#curl -XPUT 'localhost:9200/students/class1/1?pretty' -d'
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "1",
        "_version" : 1,
        "created" : true
      }
      

      [root@node3 ~]#curl -XPUT 'localhost:9200/students/class1/2?pretty' -d '
      {
        "first_name" : "Rong",
        "last_name" : "Huang",
        "gender" : "Female",
        "age" : 23,
        "courses" : "Luoying Shenjian"
      }'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "_version" : 1,
        "created" : true
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?pretty'
      {
        "took" : 16,
        "timed_out" : false,
        "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
        },
        "hits" : {
          "total" : 2,
          "max_score" : 1.0,
          "hits" : [ {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "1",
            "_score" : 1.0,
            "_source":
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }
          }, {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "2",
            "_score" : 1.0,
            "_source":
      {
        "first_name" : "Rong",
        "last_name" : "Huang",
        "gender" : "Female",
        "age" : 23,
        "courses" : "Luoying Shenjian"
      }
          } ]
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?pretty' -d '
      > {
      >   "query" : { "match_all" : {} }
      > }'
      {
        "took" : 15,
        "timed_out" : false,
        "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
        },
        "hits" : {
          "total" : 2,
          "max_score" : 1.0,
          "hits" : [ {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "1",
            "_score" : 1.0,
            "_source":
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }
          }, {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "2",
            "_score" : 1.0,
            "_source":
      {
        "first_name" : "Rong",
        "last_name" : "Huang",
        "gender" : "Female",
        "age" : 23,
        "courses" : "Luoying Shenjian"
      }
          } ]
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q="Xianglong"'
      {"took":35,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.11506981,"hits":[{"_index":"students","_type":"class1","_id":"1","_score":0.11506981,"_source":
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }}]}}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q="Xianglong"&pretty'
      {
        "took" : 12,
        "timed_out" : false,
        "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
        },
        "hits" : {
          "total" : 1,
          "max_score" : 0.11506981,
          "hits" : [ {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "1",
            "_score" : 0.11506981,
            "_source":
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }
          } ]
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q="Xianglong Shiba Zhang"&pretty'curl: (52) Empty reply from server
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=courses:"Xianglong"&pretty'{
        "took" : 9,
        "timed_out" : false,
        "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
        },
        "hits" : {
          "total" : 1,
          "max_score" : 0.15342641,
          "hits" : [ {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "1",
            "_score" : 0.15342641,
            "_source":
      {
        "first_name": "Jing",
        "last_name": "Guo",
        "gender" : "Male",
        "courses" : "Xianglong Shiba Zhang"
      }
          } ]
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=courses:"Xianglong Shiba Zhang"&pretty'
      curl: (52) Empty reply from server
      

      [root@node3 ~]# curl -XDELETE 'localhost:9200/students/class1/1'
      {"found":true,"_index":"students","_type":"class1","_id":"1","_version":2}
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/1?pretty' -d '
      > {
      >   "name" : "Guo Jing",
      >   "gender" : "Male",
      >   "age" : 25,
      >   "class" : "Gai Bang"
      >  }
      > '
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "1",
        "_version" : 1,
        "created" : true
      }
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/1?pretty' -d '
      {
        "name" : "Yang Guo",
        "gender" : "Male",
        "age" : 17,
        "class" : "Gmu Pai"
       }
      '
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "1",
        "_version" : 2,
        "created" : false
      }
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/2?pretty' -d '
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      '
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "2",
        "_version" : 2,
        "created" : false
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q="Guo"'
      {"took":23,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":0.11506981,"hits":[{"_index":"students","_type":"class1","_id":"1","_score":0.11506981,"_source":
      {
        "name" : "Yang Guo",
        "gender" : "Male",
        "age" : 17,
        "class" : "Gmu Pai"
       }
      },{"_index":"students","_type":"class1","_id":"2","_score":0.11506981,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/3?pretty' -d '
      {
        "name" : "Huang Rong",
        "gender" : "Female",
        "age" : 22,
        "class" : "Guo Xiaotian"
       }
      '
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "3",
        "_version" : 1,
        "created" : true
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q="Guo"'
      {"took":16,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":0.11506981,"hits":[{"_index":"students","_type":"class1","_id":"1","_score":0.11506981,"_source":
      {
        "name" : "Yang Guo",
        "gender" : "Male",
        "age" : 17,
        "class" : "Gmu Pai"
       }
      },{"_index":"students","_type":"class1","_id":"2","_score":0.11506981,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      },{"_index":"students","_type":"class1","_id":"3","_score":0.11506981,"_source":
      {
        "name" : "Huang Rong",
        "gender" : "Female",
        "age" : 22,
        "class" : "Guo Xiaotian"
       }
      }]}}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q="Guo%20Jing"'
      {"took":24,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.23013961,"hits":[{"_index":"students","_type":"class1","_id":"2","_score":0.23013961,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=name:"Guo"'
      {"took":18,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":0.19178301,"hits":[{"_index":"students","_type":"class1","_id":"1","_score":0.19178301,"_source":
      {
        "name" : "Yang Guo",
        "gender" : "Male",
        "age" : 17,
        "class" : "Gmu Pai"
       }
      },{"_index":"students","_type":"class1","_id":"2","_score":0.19178301,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/class1/4?pretty' -d '
      > {
      >   "name" : "GuoXiang",
      >   "gender" : "Female",
      >   "age" : 10,
      >   "class" : "Emei Pai"
      > }'
      {
        "_index" : "students",
        "_type" : "class1",
        "_id" : "4",
        "found" : false
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=name:"Guo"'
      {"took":23,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":0.19178301,"hits":[{"_index":"students","_type":"class1","_id":"1","_score":0.19178301,"_source":
      {
        "name" : "Yang Guo",
        "gender" : "Male",
        "age" : 17,
        "class" : "Gmu Pai"
       }
      },{"_index":"students","_type":"class1","_id":"2","_score":0.19178301,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=name:"Guo%20Jing"'
      {"took":16,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.38356602,"hits":[{"_index":"students","_type":"class1","_id":"2","_score":0.38356602,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=25'
      {"took":14,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.11506981,"hits":[{"_index":"students","_type":"class1","_id":"2","_score":0.11506981,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl -XPUT 'localhost:9200/students/class1/5' -d '
      > {
      >   "name" : "Xiaolong nv",
      >   "gender" : "Female",
      >   "age" : 18,
      >   "description" : " one of 25 "
      > }'
      {"_index":"students","_type":"class1","_id":"5","_version":1,"created":true}
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?q=25'
      {"took":13,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":0.11506981,"hits":[{"_index":"students","_type":"class1","_id":"5","_score":0.11506981,"_source":
      {
        "name" : "Xiaolong nv",
        "gender" : "Female",
        "age" : 18,
        "description" : " one of 25 "
      }},{"_index":"students","_type":"class1","_id":"2","_score":0.11506981,"_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      }]}}
      

      [root@node3 ~]# curl 'localhost:9200/students/_mapping/class1?pretty'
      {
        "students" : {
          "mappings" : {
            "class1" : {
              "properties" : {
                "age" : {
                  "type" : "long"
                },
                "class" : {
                  "type" : "string"
                },
                "courses" : {
                  "type" : "string"
                },
                "description" : {
                  "type" : "string"
                },
                "first_name" : {
                  "type" : "string"
                },
                "gender" : {
                  "type" : "string"
                },
                "last_name" : {
                  "type" : "string"
                },
                "name" : {
                  "type" : "string"
                }
              }
            }
          }
        }
      }
      

      04ES查询及Logstash入门
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?pretty' -d '
      {
        "query": {
      >     "terms": {
      >       "age": [25,23,22,18]
      >       }
      >   }
      > }'
      {
        "took" : 34,
        "timed_out" : false,
        "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
        },
        "hits" : {
          "total" : 3,
          "max_score" : 0.125,
          "hits" : [ {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "5",
            "_score" : 0.125,
            "_source":
      {
        "name" : "Xiaolong nv",
        "gender" : "Female",
        "age" : 18,
        "description" : " one of 25 "
      }
          }, {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "2",
            "_score" : 0.125,
            "_source":
      {
        "name" : "Guo Jing",
        "gender" : "Male",
        "age" : 25,
        "class" : "Gai Bang"
       }
      

          }, {
            "_index" : "students",
            "_type" : "class1",
            "_id" : "3",
            "_score" : 0.125,
            "_source":
      {
        "name" : "Huang Rong",
        "gender" : "Female",
        "age" : 22,
        "class" : "Guo Xiaotian"
       }
      

          } ]
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_validate/query?pretty' -d '
      > {
      >   "query": {
      >     "filterd": {
      >        "filter": { "term": { "name": "Guo" } }
      >     }
      >   }
      > }'
      {
        "valid" : false,
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_validate/query?pretty' -d'
      > {
      >   "query": {
      >     "term": { "age": 25 }
      >   }
      > }'
      {
        "valid" : true,
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        }
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_validate/query?explain&pretty' -d'
      {
        "query": {
          "term": { "age": 25 }
        }
      }'
      {
        "valid" : true,
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        },
        "explanations" : [ {
          "index" : "students",
          "valid" : true,
          "explanation" : "ConstantScore(age: \u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0019)"
        } ]
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_validate/query?explain&pretty' -d'{y' -d'
        "query": {
          "term": { "name": "Guo" }
        } "term": { "name": "Guo" }
      }'}
      {
        "valid" : true,
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        },
        "explanations" : [ {
          "index" : "students",
          "valid" : true,
          "explanation" : "name:Guo"
        } ]
      }
      

      [root@node3 ~]# curl -XGET 'localhost:9200/students/_search?pretty' -d'         {      
        "query": {
          "term": { "name": "Guo" }
        }                          
      }'
      {
        "took" : 9,
        "timed_out" : false,
        "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
        },
        "hits" : {
          "total" : 0,
          "max_score" : null,
          "hits" : [ ]
        }
      }
      

      

      [root@node4 ~]# yum makecache
      [root@node4 ~]# vim /etc/profile.d/java.sh
      添加:
      export JAVA_HOME=/usr
      [root@node4 ~]# yum -y install logstash-1.5.4-1.noarch.rpm
      [root@node4 ~]# vim /etc/profile.d/logstash.sh
      export PATH=/opt/logstash/bin:$PATH
      [root@node4 ~]# . /etc/profile.d/logstash.sh
      [root@node4 ~]# cd /etc/logstash/conf.d/
      input {
      stdin {}
      }
      

      output {
      stdout {
      codec   => rubydebug
      }
      }
      [root@node4 conf.d]# logstash -f sample.conf --configtest
      Configuration OK
      [root@node4 conf.d]# logstash -f sample.conf
      Logstash startup completed
      Hello Logstash
      {
             "message" => "Hello Logstash",
            "@version" => "1",
          "@timestamp" => "2017-01-02T13:25:21.779Z",
                "host" => "node4"
      }
      





  • 运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
    2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
    3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
    4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
    5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
    6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
    7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
    8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

    所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-669181-1-1.html 上篇帖子: Elastic Stack5.2.2升级到6.0.0注意事项 下篇帖子: Elasticstack 5.1.2 集群日志系统部署及实践
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    扫码加入运维网微信交流群X

    扫码加入运维网微信交流群

    扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

    扫描微信二维码查看详情

    客服E-mail:kefu@iyunv.com 客服QQ:1061981298


    QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


    提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


    本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



    合作伙伴: 青云cloud

    快速回复 返回顶部 返回列表