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

[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

03 ES使用详解

[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"

          }

        }

      }

    }

  }

}

04 ES查询及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"

}

转载于:https://blog.51cto.com/sihua/1888410

54 搜索引擎及Lucene基础、elasticsearch使用基础、ES使用详解、ES查询及Logstash入门...相关推荐

  1. elasticsearch系列五:搜索详解(查询建议介绍、Suggester 介绍)

    一.查询建议介绍 1. 查询建议是什么? 查询建议,为用户提供良好的使用体验.主要包括: 拼写检查: 自动建议查询词(自动补全) 拼写检查如图: 自动建议查询词(自动补全): 2. ES中查询建议的A ...

  2. basicdatasourcefactory mysql_Java基础-DBCP连接池(BasicDataSource类)详解

    Java基础-DBCP连接池(BasicDataSource类)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 实际开发中"获得连接"或"释放资源 ...

  3. Sniff网络基础原理和软件实现技巧详解

    Sniff网络基础原理和软件实现技巧详解 前言 SNIFF真是一个古老的话题,关于在网络上采用SNIFF来获取敏感信息已经不是什么新鲜事,也不乏很多成功的案例,那么,SNIFF究竟是什么呢? SNIF ...

  4. Python基础之格式化输出函数format()功能详解

    之前发过一篇文章:Python基础之常用格式化输出字符详解 但是呢,有时候我们需要用到多个%的时候,用这个就很不方便了,比如数错%数量或者一 一对应的时候... 这里补充一个字典方式的格式化输出字符的 ...

  5. Java基础13:反射与注解详解

    Java基础13:反射与注解详解 什么是反射? 反射(Reflection)是Java 程序开发语言的特征之一,它允许运行中的 Java 程序获取自身的信息,并且可以操作类或对象的内部属性. Orac ...

  6. 3dmax基础知识:3dmax常用功能详解,零基础小白的福音

    你收藏了那么多教程,却不知道3dmax怎么入门?掌握3dmax常用功能是3dmax入门的基础之一,今天就为您盘点了一些3dmax最常用到的功能和使用方法,快来和小编一起学习3dmax入门基础知识吧! ...

  7. 从基础到进阶,一文详解RocketMQ事务消息,看完不会跪键盘

    本文转载自:从基础到进阶,一文详解RocketMQ事务消息,看完不会跪键盘 事务消息是RocketMQ提供的非常重要的一个特性,在4.x版本之后开源,可以利用事务消息轻松地实现分布式事务.本文对Roc ...

  8. elasticsearch性能测试工具rally深入详解

    Elasticsearch性能测试工具rally深入详解题记 elasticsearch性能测试研究了很久,自己想过通过批量导入数据,然后记录时间,统计CPU.内存等变化,计算得出某个性能指标.但显然 ...

  9. ElasticSearch——Spring Boot 集成 ES 操作详解

    文章目录 ElasticSearch--Spring Boot 集成 ES 操作详解 1.SpringBoot 集成 ES 2.索引的API操作详解 3.文档的API操作详解 ElasticSearc ...

  10. [Java入门笔记] 面向对象编程基础(二):方法详解

    2019独角兽企业重金招聘Python工程师标准>>> 什么是方法? 简介 在上一篇的blog中,我们知道了方法是类中的一个组成部分,是类或对象的行为特征的抽象. 无论是从语法和功能 ...

最新文章

  1. MATLAB判断三角形成立的编程,Triangulation 划分三角形网络时用到的大量算法和测试例程 matlab 259万源代码下载- www.pudn.com...
  2. DOMContentLoaded 与onload区别以及使用
  3. python tk下拉列表的state_Python tkinter之ComboBox(下拉框)的使用简介
  4. 视频测试序列下载:YUV文件
  5. springmvc常用注解与类型转换
  6. 从零开始学keras之电影二分类
  7. eclipse中variable references non-existion resource可能原因及解决方案
  8. 蓝桥杯2020国赛太原理工学子成绩大跃进
  9. 8255工作方式一A口和B口输出
  10. 入门学习因果推断在智能营销/权益应用的通用框架
  11. Python进阶(十四) logging标准库
  12. nmake编译dll
  13. python分位点计算(正态分布,卡方分布,t分布,F分布)
  14. 阿里天池大数据竞赛——口碑商家客流量预测 A1
  15. Android欢迎页面以及引导页面
  16. element分页组件,搜索过后current-page 绑定的数据变了,但是页面当前页码并没有变的问题
  17. 基于参考辐射源/定标的校正算法
  18. k8s-client-go源码剖析(一)
  19. Idea注释输入中文,显示为日文
  20. Scrapy模块爬取中华英才网招聘信息(分页)

热门文章

  1. Java探索之旅(18)——多线程(2)
  2. 基于FTP4J组件的FTP操作客户端
  3. 在hisi上QT交叉编译过程(带webengine)
  4. 网络收包流程-报文从网卡驱动到网络层(或者网桥)的流程(非NAPI、NAPI)(一)
  5. Linux电源管理-wakeup count
  6. php mysql 命令行模式_phpstudy(mysql命令行的增删改查)
  7. DPDK框架原理简介 (0002转)
  8. AndroidOpenCV摄像头预览全屏问题
  9. mysql实例备份和单库备份_史上最简单的MySQL数据备份与还原教程(上)(三十五)...
  10. win10浏览器闪退_win10纯净版系统中edge浏览器闪退的解决方法