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

[经验分享] 搜索引擎及Lucene基础、elasticsearch使用基础、ES使用详解、ES...

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-1-3 13:11:00 | 显示全部楼层 |阅读模式
搜索引擎及Lucene基础、elasticsearch使用基础、ES使用详解、ES查询及Logstash入门
01        搜索引擎及Lucene基础

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

[iyunv@node1 ~]# vim /etc/profile.d/java.sh
        export JAVA_HOME=/usr
[iyunv@node1 ~]# yum install java-1.7.0-openjdk-devel.x86_64  -y
[iyunv@node1 ~]# ls elasticsearch-1.7.2.noarch.rpm
elasticsearch-1.7.2.noarch.rpm
[iyunv@node1 ~]# yum install elasticsearch-1.7.2.noarch.rpm -y
[iyunv@node1 ~]# cd /etc/elasticsearch/
[iyunv@node1 elasticsearch]# ls
elasticsearch.yml  logging.yml
[iyunv@node1 elasticsearch]# vim elasticsearch.yml
修改
        #cluster.name: elasticsearch

        cluster.name: myes
修改
        #node.name: "Franz Kafka"

        node.name: "node1"
[iyunv@node1 elasticsearch]# systemctl daemon-reload
[iyunv@node1 elasticsearch]# systemctl start elasticsearch.service
[iyunv@node1 elasticsearch]# scp /etc/profile.d/java.sh node2:/etc/profile.d/
[iyunv@node1 elasticsearch]# scp /etc/profile.d/java.sh node3:/etc/profile.d/
[iyunv@node1 ~]# scp elasticsearch-1.7.2.noarch.rpm node2:/root
[iyunv@node1 ~]# scp elasticsearch-1.7.2.noarch.rpm node3:/root

[iyunv@node2 ~]# yum makecache
[iyunv@node2 ~]# yum install java-1.7.0-openjdk-devel.x86_64 -y
[iyunv@node2 ~]# yum -y install elasticsearch-1.7.2.noarch.rpm
[iyunv@node2 ~]# vim /etc/elasticsearch/elasticsearch.yml
修改
        #cluster.name: elasticsearch

        cluster.name: myes
修改
        #node.name: "Franz Kafka"

        node.name: "node2"
[iyunv@node2 ~]# systemctl daemon-reload
[iyunv@node2 ~]# systemctl start elasticsearch.service           
[iyunv@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       

[iyunv@node3 ~]# yum makecache
[iyunv@node3 ~]# yum install java-1.7.0-openjdk-devel.x86_64 -y
[iyunv@node3 ~]# yum -y install elasticsearch-1.7.2.noarch.rpm
[iyunv@node3 ~]# vim /etc/elasticsearch/elasticsearch.yml
修改
        #cluster.name: elasticsearch

        cluster.name: myes
修改
        #node.name: "Franz Kafka"

        node.name: "node3"
[iyunv@node3 elasticsearch]# systemctl daemon-reload
[iyunv@node3 elasticsearch]# systemctl start elasticsearch.service

[iyunv@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"
}

[iyunv@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"
}

[iyunv@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"
}

[iyunv@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}

[iyunv@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

[iyunv@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

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

[iyunv@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

#查看主节点
[iyunv@node3 ~]# curl -X GET 'http://192.168.1.133:9200/_cat/master'  hdbLm-k-Q4eY9RxeMvAJDw node1 192.168.1.131 node1
#详细格式
[iyunv@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

#显示健康状态
[iyunv@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
#详细格式
[iyunv@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        


03        ES使用详解

[iyunv@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}

[iyunv@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
}

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

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

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

[iyunv@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" : { }
    }
  }
}

[iyunv@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" : { }
    }
  }
}

[iyunv@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" : [ ]
  }
}

[iyunv@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)

    [iyunv@node3 ~]# /usr/share/elasticsearch/bin/plugin -i marvel -u ftp://192.168.56.2/pub/Sources/7 ... s/marvel-latest.zip

    [iyunv@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 ...

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

    [iyunv@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

    [iyunv@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

    [iyunv@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

    [iyunv@node1 ~]# /usr/share/elasticsearch/bin/plugin -l
    Installed plugins:
        - bigdesk
        - head
        - kopf
        - marvel
    [iyunv@node1 ~]# systemctl restart elasticsearch.service
    http://192.168.1.131:9200/_plugi ... arvel.overview.json

    [iyunv@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

    [iyunv@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
    }

    [iyunv@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
    }

    [iyunv@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"
    }
    }

    [iyunv@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"
    }
    }

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

    [iyunv@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"}
    }

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

    [iyunv@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

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

    [iyunv@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


    [iyunv@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
    }

    [iyunv@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
    }

    [iyunv@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"
    }
        } ]
      }
    }

    [iyunv@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"
    }
        } ]
      }
    }

    [iyunv@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"
    }}]}}

    [iyunv@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"
    }
        } ]
      }
    }

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

    [iyunv@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"
    }
        } ]
      }
    }

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

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

    [iyunv@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
    }

    [iyunv@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
    }

    [iyunv@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
    }

    [iyunv@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"
    }
    }]}}

    [iyunv@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
    }

    [iyunv@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"
    }
    }]}}

    [iyunv@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"
    }
    }]}}

    [iyunv@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"
    }
    }]}}

    [iyunv@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
    }

    [iyunv@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"
    }
    }]}}

    [iyunv@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"
    }
    }]}}

    [iyunv@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"
    }
    }]}}

    [iyunv@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}

    [iyunv@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"
    }
    }]}}

    [iyunv@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"
              }
            }
          }
        }
      }
    }

    04        ES查询及Logstash入门

    [iyunv@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"
    }

        } ]
      }
    }

    [iyunv@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
      }
    }

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

    [iyunv@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)"
      } ]
    }

    [iyunv@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"
      } ]
    }

    [iyunv@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" : [ ]
      }
    }


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

            output {
                    stdout {
                            codec   => rubydebug
                    }
            }
    [iyunv@node4 conf.d]# logstash -f sample.conf --configtest
    Configuration OK
    [iyunv@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-323326-1-1.html 上篇帖子: ELK 安装配置 下篇帖子: Elasticsearch-Cluster标准部署文档 搜索引擎
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

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

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

    扫描微信二维码查看详情

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


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


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


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



    合作伙伴: 青云cloud

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