赞
踩
java升级到jdk8,下载es
https://www.elastic.co/downloads/elasticsearch
解压es压缩包,启动es
./bin/elasticsearch
显示:
- {
- "name" : "pleYB0j",
- "cluster_name" : "elasticsearch",
- "cluster_uuid" : "tRrh3XC_Rka1huf1zMOTSg",
- "version" : {
- "number" : "5.3.0",
- "build_hash" : "3adb13b",
- "build_date" : "2017-03-23T03:31:50.652Z",
- "build_snapshot" : false,
- "lucene_version" : "6.4.1"
- },
- "tagline" : "You Know, for Search"
- }
curl -XPUT 'localhost:9200/customer?pretty'
- health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
- yellow open customer -D-eQGuNT-uG-g0MkuiBGg 5 1 0 0 650b 650b
第二个命令的结果告知我们,我们现在有一个叫做customer的索引,并且它有5个主分片和1份复制(都是默认值),其中包含0个文档。
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d ' {"name": "John Doe"}'
输出:
- {
- "_index" : "customer",
- "_type" : "external",
- "_id" : "1",
- "_version" : 1,
- "result" : "created",
- "_shards" : {
- "total" : 2,
- "successful" : 1,
- "failed" : 0
- },
- "created" : true
- }
将一个简单的客户文档索引到customer索引、“external”类型中,这个文档的ID是1
curl -XGET 'localhost:9200/customer/external/1?pretty'
结果:
- {
- "_index" : "customer",
- "_type" : "external",
- "_id" : "1",
- "_version" : 1,
- "found" : true,
- "_source" : {
- "name" : "John Doe"
- }
- }
除了一个叫做found的字段来指明我们找到了一个ID为1的文档,和另外一个字段——_source——返回我们前一步中索引的完整JSON文档之外,其它的都没有什么特别之处。
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
- {"index":{"_id":"1"}}
- {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
- {"index":{"_id":"6"}}
- {"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"hattiebond@netagy.com","city":"Dante","state":"TN"}
curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' { "query": { "match": { "account_number": 1 } } }'
结果:
{ "took" : 11, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "bank", "_type" : "account", "_id" : "1", "_score" : 1.0, "_source" : { "account_number" : 1, "balance" : 39225, "firstname" : "Amber", "lastname" : "Duke", "age" : 32, "gender" : "M", "address" : "880 Holmes Lane", "employer" : "Pyrami", "email" : "amberduke@pyrami.com", "city" : "Brogan", "state" : "IL" } } ] } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。