博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
测试elasticsearch-5.1.2 API接口
阅读量:6280 次
发布时间:2019-06-22

本文共 66807 字,大约阅读时间需要 222 分钟。

hot3.png

接上篇,

测试elasticsearch-5.1.2

下载测试数据测试

从一部分测试数据,然后导入到elasticsearch-5.1.2集群中测试

将下载的zip包解压,把accounts.json文件上传到指定目录导入到elasticsearch-5.1.2集群中

[root@localhost elasticsearch-cluster]# lltotal 33676-rw-rw-r--. 1 listen listen   244848 Jan 19 00:31 accounts.jsondrwxrwxr-x. 2 listen listen        6 Jan 18 18:42 data-rwxr-xr-x. 1 listen listen 33299777 Jan 18 18:31 elasticsearch-5.1.2.tar.gzdrwxrwxr-x. 5 listen listen     4096 Jan 18 23:27 elasticsearch-head-master-rw-rw-r--. 1 listen listen   908930 Jan 18 22:41 elasticsearch-head-master.zipdrwxr-xr-x. 9 listen listen     4096 Jan 18 18:43 elasticsearch-node1drwxr-xr-x. 9 listen listen     4096 Jan 18 18:50 elasticsearch-node2-rw-------. 1 listen listen     8441 Jan 19 01:22 nohup.out-rw-r--r--. 1 root   root       2544 Jan 18 23:28 npm-debug.log[root@localhost elasticsearch-cluster]# [root@localhost elasticsearch-cluster]# curl 'localhost:9201/_cat/indices?v'health status index uuid pri rep docs.count docs.deleted store.size pri.store.size[root@localhost elasticsearch-cluster]# [root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/account/_bulk?pretty' --data-binary "@accounts.json"    {      "index" : {        "_index" : "bank",        "_type" : "account",        "_id" : "990",        "_version" : 1,        "result" : "created",        "_shards" : {          "total" : 2,          "successful" : 2,          "failed" : 0        },        "created" : true,        "status" : 201      }    },    {      "index" : {        "_index" : "bank",        "_type" : "account",        "_id" : "995",        "_version" : 1,        "result" : "created",        "_shards" : {          "total" : 2,          "successful" : 2,          "failed" : 0        },        "created" : true,        "status" : 201      }    }  ]}[root@localhost elasticsearch-cluster]# [root@localhost elasticsearch-cluster]# curl 'localhost:9201/_cat/indices?v'health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.sizegreen  open   bank  7aHbsdm8S0iNEuLLdU2MLw   5   1       1000            0      1.2mb        656.8kb[root@localhost elasticsearch-cluster]#

查询全部,默认返回前10条

查询全部,默认返回前10个文档

[root@localhost elasticsearch-cluster]# curl 'localhost:9201/bank/_search?q=*&pretty'{  "took" : 469,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1000,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "25",        "_score" : 1.0,        "_source" : {          "account_number" : 25,          "balance" : 40540,          "firstname" : "Virginia",          "lastname" : "Ayala",          "age" : 39,          "gender" : "F",          "address" : "171 Putnam Avenue",          "employer" : "Filodyne",          "email" : "virginiaayala@filodyne.com",          "city" : "Nicholson",          "state" : "PA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "44",        "_score" : 1.0,        "_source" : {          "account_number" : 44,          "balance" : 34487,          "firstname" : "Aurelia",          "lastname" : "Harding",          "age" : 37,          "gender" : "M",          "address" : "502 Baycliff Terrace",          "employer" : "Orbalix",          "email" : "aureliaharding@orbalix.com",          "city" : "Yardville",          "state" : "DE"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "99",        "_score" : 1.0,        "_source" : {          "account_number" : 99,          "balance" : 47159,          "firstname" : "Ratliff",          "lastname" : "Heath",          "age" : 39,          "gender" : "F",          "address" : "806 Rockwell Place",          "employer" : "Zappix",          "email" : "ratliffheath@zappix.com",          "city" : "Shaft",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "119",        "_score" : 1.0,        "_source" : {          "account_number" : 119,          "balance" : 49222,          "firstname" : "Laverne",          "lastname" : "Johnson",          "age" : 28,          "gender" : "F",          "address" : "302 Howard Place",          "employer" : "Senmei",          "email" : "lavernejohnson@senmei.com",          "city" : "Herlong",          "state" : "DC"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "126",        "_score" : 1.0,        "_source" : {          "account_number" : 126,          "balance" : 3607,          "firstname" : "Effie",          "lastname" : "Gates",          "age" : 39,          "gender" : "F",          "address" : "620 National Drive",          "employer" : "Digitalus",          "email" : "effiegates@digitalus.com",          "city" : "Blodgett",          "state" : "MD"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "145",        "_score" : 1.0,        "_source" : {          "account_number" : 145,          "balance" : 47406,          "firstname" : "Rowena",          "lastname" : "Wilkinson",          "age" : 32,          "gender" : "M",          "address" : "891 Elton Street",          "employer" : "Asimiline",          "email" : "rowenawilkinson@asimiline.com",          "city" : "Ripley",          "state" : "NH"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "183",        "_score" : 1.0,        "_source" : {          "account_number" : 183,          "balance" : 14223,          "firstname" : "Hudson",          "lastname" : "English",          "age" : 26,          "gender" : "F",          "address" : "823 Herkimer Place",          "employer" : "Xinware",          "email" : "hudsonenglish@xinware.com",          "city" : "Robbins",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "190",        "_score" : 1.0,        "_source" : {          "account_number" : 190,          "balance" : 3150,          "firstname" : "Blake",          "lastname" : "Davidson",          "age" : 30,          "gender" : "F",          "address" : "636 Diamond Street",          "employer" : "Quantasis",          "email" : "blakedavidson@quantasis.com",          "city" : "Crumpler",          "state" : "KY"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "208",        "_score" : 1.0,        "_source" : {          "account_number" : 208,          "balance" : 40760,          "firstname" : "Garcia",          "lastname" : "Hess",          "age" : 26,          "gender" : "F",          "address" : "810 Nostrand Avenue",          "employer" : "Quiltigen",          "email" : "garciahess@quiltigen.com",          "city" : "Brooktrails",          "state" : "GA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "222",        "_score" : 1.0,        "_source" : {          "account_number" : 222,          "balance" : 14764,          "firstname" : "Rachelle",          "lastname" : "Rice",          "age" : 36,          "gender" : "M",          "address" : "333 Narrows Avenue",          "employer" : "Enaut",          "email" : "rachellerice@enaut.com",          "city" : "Wright",          "state" : "AZ"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,只返回一条

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '>     {>         "query": {"match_all": {}},>         "size": 1>     }'{  "took" : 90,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1000,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "25",        "_score" : 1.0,        "_source" : {          "account_number" : 25,          "balance" : 40540,          "firstname" : "Virginia",          "lastname" : "Ayala",          "age" : 39,          "gender" : "F",          "address" : "171 Putnam Avenue",          "employer" : "Filodyne",          "email" : "virginiaayala@filodyne.com",          "city" : "Nicholson",          "state" : "PA"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回从11到20的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '>     {"query": {"match_all": {}},>      "from": 10,>      "size": 10>     }'{  "took" : 11,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1000,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "227",        "_score" : 1.0,        "_source" : {          "account_number" : 227,          "balance" : 19780,          "firstname" : "Coleman",          "lastname" : "Berg",          "age" : 22,          "gender" : "M",          "address" : "776 Little Street",          "employer" : "Exoteric",          "email" : "colemanberg@exoteric.com",          "city" : "Eagleville",          "state" : "WV"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "253",        "_score" : 1.0,        "_source" : {          "account_number" : 253,          "balance" : 20240,          "firstname" : "Melissa",          "lastname" : "Gould",          "age" : 31,          "gender" : "M",          "address" : "440 Fuller Place",          "employer" : "Buzzopia",          "email" : "melissagould@buzzopia.com",          "city" : "Lumberton",          "state" : "MD"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "260",        "_score" : 1.0,        "_source" : {          "account_number" : 260,          "balance" : 2726,          "firstname" : "Kari",          "lastname" : "Skinner",          "age" : 30,          "gender" : "F",          "address" : "735 Losee Terrace",          "employer" : "Singavera",          "email" : "kariskinner@singavera.com",          "city" : "Rushford",          "state" : "WV"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "265",        "_score" : 1.0,        "_source" : {          "account_number" : 265,          "balance" : 46910,          "firstname" : "Marion",          "lastname" : "Schneider",          "age" : 26,          "gender" : "F",          "address" : "574 Everett Avenue",          "employer" : "Evidends",          "email" : "marionschneider@evidends.com",          "city" : "Maplewood",          "state" : "WY"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "335",        "_score" : 1.0,        "_source" : {          "account_number" : 335,          "balance" : 35433,          "firstname" : "Vera",          "lastname" : "Hansen",          "age" : 24,          "gender" : "M",          "address" : "252 Bushwick Avenue",          "employer" : "Zanilla",          "email" : "verahansen@zanilla.com",          "city" : "Manila",          "state" : "TN"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "366",        "_score" : 1.0,        "_source" : {          "account_number" : 366,          "balance" : 42368,          "firstname" : "Lydia",          "lastname" : "Cooke",          "age" : 31,          "gender" : "M",          "address" : "470 Coleman Street",          "employer" : "Comstar",          "email" : "lydiacooke@comstar.com",          "city" : "Datil",          "state" : "TN"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "385",        "_score" : 1.0,        "_source" : {          "account_number" : 385,          "balance" : 11022,          "firstname" : "Rosalinda",          "lastname" : "Valencia",          "age" : 22,          "gender" : "M",          "address" : "933 Lloyd Street",          "employer" : "Zoarere",          "email" : "rosalindavalencia@zoarere.com",          "city" : "Waverly",          "state" : "GA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "397",        "_score" : 1.0,        "_source" : {          "account_number" : 397,          "balance" : 37418,          "firstname" : "Leonard",          "lastname" : "Gray",          "age" : 36,          "gender" : "F",          "address" : "840 Morgan Avenue",          "employer" : "Recritube",          "email" : "leonardgray@recritube.com",          "city" : "Edenburg",          "state" : "AL"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "400",        "_score" : 1.0,        "_source" : {          "account_number" : 400,          "balance" : 20685,          "firstname" : "Kane",          "lastname" : "King",          "age" : 21,          "gender" : "F",          "address" : "405 Cornelia Street",          "employer" : "Tri@Tribalog",          "email" : "kaneking@tri@tribalog.com",          "city" : "Gulf",          "state" : "VT"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "450",        "_score" : 1.0,        "_source" : {          "account_number" : 450,          "balance" : 2643,          "firstname" : "Bradford",          "lastname" : "Nielsen",          "age" : 25,          "gender" : "M",          "address" : "487 Keen Court",          "employer" : "Exovent",          "email" : "bradfordnielsen@exovent.com",          "city" : "Hamilton",          "state" : "DE"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,按balance字段倒序排序

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {"match_all": {}},>     "sort": {"balance": {"order": "desc"}}> }'{  "took" : 179,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1000,    "max_score" : null,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "248",        "_score" : null,        "_source" : {          "account_number" : 248,          "balance" : 49989,          "firstname" : "West",          "lastname" : "England",          "age" : 36,          "gender" : "M",          "address" : "717 Hendrickson Place",          "employer" : "Obliq",          "email" : "westengland@obliq.com",          "city" : "Maury",          "state" : "WA"        },        "sort" : [          49989        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "854",        "_score" : null,        "_source" : {          "account_number" : 854,          "balance" : 49795,          "firstname" : "Jimenez",          "lastname" : "Barry",          "age" : 25,          "gender" : "F",          "address" : "603 Cooper Street",          "employer" : "Verton",          "email" : "jimenezbarry@verton.com",          "city" : "Moscow",          "state" : "AL"        },        "sort" : [          49795        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "240",        "_score" : null,        "_source" : {          "account_number" : 240,          "balance" : 49741,          "firstname" : "Oconnor",          "lastname" : "Clay",          "age" : 35,          "gender" : "F",          "address" : "659 Highland Boulevard",          "employer" : "Franscene",          "email" : "oconnorclay@franscene.com",          "city" : "Kilbourne",          "state" : "NH"        },        "sort" : [          49741        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "97",        "_score" : null,        "_source" : {          "account_number" : 97,          "balance" : 49671,          "firstname" : "Karen",          "lastname" : "Trujillo",          "age" : 40,          "gender" : "F",          "address" : "512 Cumberland Walk",          "employer" : "Tsunamia",          "email" : "karentrujillo@tsunamia.com",          "city" : "Fredericktown",          "state" : "MO"        },        "sort" : [          49671        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "842",        "_score" : null,        "_source" : {          "account_number" : 842,          "balance" : 49587,          "firstname" : "Meagan",          "lastname" : "Buckner",          "age" : 23,          "gender" : "F",          "address" : "833 Bushwick Court",          "employer" : "Biospan",          "email" : "meaganbuckner@biospan.com",          "city" : "Craig",          "state" : "TX"        },        "sort" : [          49587        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "168",        "_score" : null,        "_source" : {          "account_number" : 168,          "balance" : 49568,          "firstname" : "Carissa",          "lastname" : "Simon",          "age" : 20,          "gender" : "M",          "address" : "975 Flatbush Avenue",          "employer" : "Zillacom",          "email" : "carissasimon@zillacom.com",          "city" : "Neibert",          "state" : "IL"        },        "sort" : [          49568        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "803",        "_score" : null,        "_source" : {          "account_number" : 803,          "balance" : 49567,          "firstname" : "Marissa",          "lastname" : "Spears",          "age" : 25,          "gender" : "M",          "address" : "963 Highland Avenue",          "employer" : "Centregy",          "email" : "marissaspears@centregy.com",          "city" : "Bloomington",          "state" : "MS"        },        "sort" : [          49567        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "926",        "_score" : null,        "_source" : {          "account_number" : 926,          "balance" : 49433,          "firstname" : "Welch",          "lastname" : "Mcgowan",          "age" : 21,          "gender" : "M",          "address" : "833 Quincy Street",          "employer" : "Atomica",          "email" : "welchmcgowan@atomica.com",          "city" : "Hampstead",          "state" : "VT"        },        "sort" : [          49433        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "954",        "_score" : null,        "_source" : {          "account_number" : 954,          "balance" : 49404,          "firstname" : "Jenna",          "lastname" : "Martin",          "age" : 22,          "gender" : "M",          "address" : "688 Hart Street",          "employer" : "Zinca",          "email" : "jennamartin@zinca.com",          "city" : "Oasis",          "state" : "MD"        },        "sort" : [          49404        ]      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "572",        "_score" : null,        "_source" : {          "account_number" : 572,          "balance" : 49355,          "firstname" : "Therese",          "lastname" : "Espinoza",          "age" : 20,          "gender" : "M",          "address" : "994 Chester Court",          "employer" : "Gonkle",          "email" : "thereseespinoza@gonkle.com",          "city" : "Hayes",          "state" : "UT"        },        "sort" : [          49355        ]      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,只返回两个字段

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {"match_all": {}},>     "_source": ["account_number", "balance"]> }'{  "took" : 75,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1000,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "25",        "_score" : 1.0,        "_source" : {          "account_number" : 25,          "balance" : 40540        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "44",        "_score" : 1.0,        "_source" : {          "account_number" : 44,          "balance" : 34487        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "99",        "_score" : 1.0,        "_source" : {          "account_number" : 99,          "balance" : 47159        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "119",        "_score" : 1.0,        "_source" : {          "account_number" : 119,          "balance" : 49222        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "126",        "_score" : 1.0,        "_source" : {          "account_number" : 126,          "balance" : 3607        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "145",        "_score" : 1.0,        "_source" : {          "account_number" : 145,          "balance" : 47406        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "183",        "_score" : 1.0,        "_source" : {          "account_number" : 183,          "balance" : 14223        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "190",        "_score" : 1.0,        "_source" : {          "account_number" : 190,          "balance" : 3150        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "208",        "_score" : 1.0,        "_source" : {          "account_number" : 208,          "balance" : 40760        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "222",        "_score" : 1.0,        "_source" : {          "account_number" : 222,          "balance" : 14764        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回account_number=20的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {"match": {"account_number": 20}}> }'{  "took" : 112,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "20",        "_score" : 1.0,        "_source" : {          "account_number" : 20,          "balance" : 16418,          "firstname" : "Elinor",          "lastname" : "Ratliff",          "age" : 36,          "gender" : "M",          "address" : "282 Kings Place",          "employer" : "Scentric",          "email" : "elinorratliff@scentric.com",          "city" : "Ribera",          "state" : "WA"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回address含有mill的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {"match": {"address": "mill"}}> }'{  "took" : 99,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 4,    "max_score" : 4.3100996,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "472",        "_score" : 4.3100996,        "_source" : {          "account_number" : 472,          "balance" : 25571,          "firstname" : "Lee",          "lastname" : "Long",          "age" : 32,          "gender" : "F",          "address" : "288 Mill Street",          "employer" : "Comverges",          "email" : "leelong@comverges.com",          "city" : "Movico",          "state" : "MT"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "136",        "_score" : 4.2662063,        "_source" : {          "account_number" : 136,          "balance" : 45801,          "firstname" : "Winnie",          "lastname" : "Holland",          "age" : 38,          "gender" : "M",          "address" : "198 Mill Lane",          "employer" : "Neteria",          "email" : "winnieholland@neteria.com",          "city" : "Urie",          "state" : "IL"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "970",        "_score" : 3.861861,        "_source" : {          "account_number" : 970,          "balance" : 19648,          "firstname" : "Forbes",          "lastname" : "Wallace",          "age" : 28,          "gender" : "M",          "address" : "990 Mill Road",          "employer" : "Pheast",          "email" : "forbeswallace@pheast.com",          "city" : "Lopezo",          "state" : "AK"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "345",        "_score" : 3.861861,        "_source" : {          "account_number" : 345,          "balance" : 9812,          "firstname" : "Parker",          "lastname" : "Hines",          "age" : 38,          "gender" : "M",          "address" : "715 Mill Avenue",          "employer" : "Baluba",          "email" : "parkerhines@baluba.com",          "city" : "Blackgum",          "state" : "KY"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回address含有mill或lane的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {"match": {"address": "mill lane"}}> }'{  "took" : 85,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 19,    "max_score" : 7.3900023,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "136",        "_score" : 7.3900023,        "_source" : {          "account_number" : 136,          "balance" : 45801,          "firstname" : "Winnie",          "lastname" : "Holland",          "age" : 38,          "gender" : "M",          "address" : "198 Mill Lane",          "employer" : "Neteria",          "email" : "winnieholland@neteria.com",          "city" : "Urie",          "state" : "IL"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "472",        "_score" : 4.3100996,        "_source" : {          "account_number" : 472,          "balance" : 25571,          "firstname" : "Lee",          "lastname" : "Long",          "age" : 32,          "gender" : "F",          "address" : "288 Mill Street",          "employer" : "Comverges",          "email" : "leelong@comverges.com",          "city" : "Movico",          "state" : "MT"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "556",        "_score" : 3.9074605,        "_source" : {          "account_number" : 556,          "balance" : 36420,          "firstname" : "Collier",          "lastname" : "Odonnell",          "age" : 35,          "gender" : "M",          "address" : "591 Nolans Lane",          "employer" : "Sultraxin",          "email" : "collierodonnell@sultraxin.com",          "city" : "Fulford",          "state" : "MD"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "934",        "_score" : 3.9074605,        "_source" : {          "account_number" : 934,          "balance" : 43987,          "firstname" : "Freida",          "lastname" : "Daniels",          "age" : 34,          "gender" : "M",          "address" : "448 Cove Lane",          "employer" : "Vurbo",          "email" : "freidadaniels@vurbo.com",          "city" : "Snelling",          "state" : "NJ"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "970",        "_score" : 3.861861,        "_source" : {          "account_number" : 970,          "balance" : 19648,          "firstname" : "Forbes",          "lastname" : "Wallace",          "age" : 28,          "gender" : "M",          "address" : "990 Mill Road",          "employer" : "Pheast",          "email" : "forbeswallace@pheast.com",          "city" : "Lopezo",          "state" : "AK"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "345",        "_score" : 3.861861,        "_source" : {          "account_number" : 345,          "balance" : 9812,          "firstname" : "Parker",          "lastname" : "Hines",          "age" : 38,          "gender" : "M",          "address" : "715 Mill Avenue",          "employer" : "Baluba",          "email" : "parkerhines@baluba.com",          "city" : "Blackgum",          "state" : "KY"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "908",        "_score" : 3.861861,        "_source" : {          "account_number" : 908,          "balance" : 45975,          "firstname" : "Mosley",          "lastname" : "Holloway",          "age" : 31,          "gender" : "M",          "address" : "929 Eldert Lane",          "employer" : "Anivet",          "email" : "mosleyholloway@anivet.com",          "city" : "Biehle",          "state" : "MS"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "637",        "_score" : 3.861861,        "_source" : {          "account_number" : 637,          "balance" : 3169,          "firstname" : "Kathy",          "lastname" : "Carter",          "age" : 27,          "gender" : "F",          "address" : "410 Jamison Lane",          "employer" : "Limage",          "email" : "kathycarter@limage.com",          "city" : "Ernstville",          "state" : "WA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "449",        "_score" : 3.8473392,        "_source" : {          "account_number" : 449,          "balance" : 41950,          "firstname" : "Barnett",          "lastname" : "Cantrell",          "age" : 39,          "gender" : "F",          "address" : "945 Bedell Lane",          "employer" : "Zentility",          "email" : "barnettcantrell@zentility.com",          "city" : "Swartzville",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "742",        "_score" : 3.8473392,        "_source" : {          "account_number" : 742,          "balance" : 24765,          "firstname" : "Merle",          "lastname" : "Wooten",          "age" : 26,          "gender" : "M",          "address" : "317 Pooles Lane",          "employer" : "Tropolis",          "email" : "merlewooten@tropolis.com",          "city" : "Bentley",          "state" : "ND"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回address中包含mill和lane的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {>         "bool": {>             "must": [>                 {"match": {"address": "mill"}},>                 {"match": {"address": "lane"}}>             ]>         }>     }> }'{  "took" : 72,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1,    "max_score" : 7.3900023,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "136",        "_score" : 7.3900023,        "_source" : {          "account_number" : 136,          "balance" : 45801,          "firstname" : "Winnie",          "lastname" : "Holland",          "age" : 38,          "gender" : "M",          "address" : "198 Mill Lane",          "employer" : "Neteria",          "email" : "winnieholland@neteria.com",          "city" : "Urie",          "state" : "IL"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回address既没有mill也没有lane的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {>         "bool": {> >             "must_not": [>                 {"match": {"address": "mill"}},>                 {"match": {"address": "lane"}}>             ]>         }>     }> }'{  "took" : 34,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 981,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "25",        "_score" : 1.0,        "_source" : {          "account_number" : 25,          "balance" : 40540,          "firstname" : "Virginia",          "lastname" : "Ayala",          "age" : 39,          "gender" : "F",          "address" : "171 Putnam Avenue",          "employer" : "Filodyne",          "email" : "virginiaayala@filodyne.com",          "city" : "Nicholson",          "state" : "PA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "44",        "_score" : 1.0,        "_source" : {          "account_number" : 44,          "balance" : 34487,          "firstname" : "Aurelia",          "lastname" : "Harding",          "age" : 37,          "gender" : "M",          "address" : "502 Baycliff Terrace",          "employer" : "Orbalix",          "email" : "aureliaharding@orbalix.com",          "city" : "Yardville",          "state" : "DE"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "99",        "_score" : 1.0,        "_source" : {          "account_number" : 99,          "balance" : 47159,          "firstname" : "Ratliff",          "lastname" : "Heath",          "age" : 39,          "gender" : "F",          "address" : "806 Rockwell Place",          "employer" : "Zappix",          "email" : "ratliffheath@zappix.com",          "city" : "Shaft",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "119",        "_score" : 1.0,        "_source" : {          "account_number" : 119,          "balance" : 49222,          "firstname" : "Laverne",          "lastname" : "Johnson",          "age" : 28,          "gender" : "F",          "address" : "302 Howard Place",          "employer" : "Senmei",          "email" : "lavernejohnson@senmei.com",          "city" : "Herlong",          "state" : "DC"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "126",        "_score" : 1.0,        "_source" : {          "account_number" : 126,          "balance" : 3607,          "firstname" : "Effie",          "lastname" : "Gates",          "age" : 39,          "gender" : "F",          "address" : "620 National Drive",          "employer" : "Digitalus",          "email" : "effiegates@digitalus.com",          "city" : "Blodgett",          "state" : "MD"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "145",        "_score" : 1.0,        "_source" : {          "account_number" : 145,          "balance" : 47406,          "firstname" : "Rowena",          "lastname" : "Wilkinson",          "age" : 32,          "gender" : "M",          "address" : "891 Elton Street",          "employer" : "Asimiline",          "email" : "rowenawilkinson@asimiline.com",          "city" : "Ripley",          "state" : "NH"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "183",        "_score" : 1.0,        "_source" : {          "account_number" : 183,          "balance" : 14223,          "firstname" : "Hudson",          "lastname" : "English",          "age" : 26,          "gender" : "F",          "address" : "823 Herkimer Place",          "employer" : "Xinware",          "email" : "hudsonenglish@xinware.com",          "city" : "Robbins",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "190",        "_score" : 1.0,        "_source" : {          "account_number" : 190,          "balance" : 3150,          "firstname" : "Blake",          "lastname" : "Davidson",          "age" : 30,          "gender" : "F",          "address" : "636 Diamond Street",          "employer" : "Quantasis",          "email" : "blakedavidson@quantasis.com",          "city" : "Crumpler",          "state" : "KY"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "208",        "_score" : 1.0,        "_source" : {          "account_number" : 208,          "balance" : 40760,          "firstname" : "Garcia",          "lastname" : "Hess",          "age" : 26,          "gender" : "F",          "address" : "810 Nostrand Avenue",          "employer" : "Quiltigen",          "email" : "garciahess@quiltigen.com",          "city" : "Brooktrails",          "state" : "GA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "222",        "_score" : 1.0,        "_source" : {          "account_number" : 222,          "balance" : 14764,          "firstname" : "Rachelle",          "lastname" : "Rice",          "age" : 36,          "gender" : "M",          "address" : "333 Narrows Avenue",          "employer" : "Enaut",          "email" : "rachellerice@enaut.com",          "city" : "Wright",          "state" : "AZ"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,返回age=40,且state!=ID的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {>         "bool": {>             "must": [>                 {"match": {"age": 40}}>             ]> ,>              "must_not": [>                 {"match": {"state": "ID"}}>             ]>         }>     }> }'{  "took" : 46,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 43,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "948",        "_score" : 1.0,        "_source" : {          "account_number" : 948,          "balance" : 37074,          "firstname" : "Sargent",          "lastname" : "Powers",          "age" : 40,          "gender" : "M",          "address" : "532 Fiske Place",          "employer" : "Accuprint",          "email" : "sargentpowers@accuprint.com",          "city" : "Umapine",          "state" : "AK"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "40",        "_score" : 1.0,        "_source" : {          "account_number" : 40,          "balance" : 33882,          "firstname" : "Pace",          "lastname" : "Molina",          "age" : 40,          "gender" : "M",          "address" : "263 Ovington Court",          "employer" : "Cytrak",          "email" : "pacemolina@cytrak.com",          "city" : "Silkworth",          "state" : "OR"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "468",        "_score" : 1.0,        "_source" : {          "account_number" : 468,          "balance" : 18400,          "firstname" : "Foreman",          "lastname" : "Fowler",          "age" : 40,          "gender" : "M",          "address" : "443 Jackson Court",          "employer" : "Zillactic",          "email" : "foremanfowler@zillactic.com",          "city" : "Wakarusa",          "state" : "WA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "792",        "_score" : 1.0,        "_source" : {          "account_number" : 792,          "balance" : 13109,          "firstname" : "Becky",          "lastname" : "Jimenez",          "age" : 40,          "gender" : "F",          "address" : "539 Front Street",          "employer" : "Isologia",          "email" : "beckyjimenez@isologia.com",          "city" : "Summertown",          "state" : "MI"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "302",        "_score" : 1.0,        "_source" : {          "account_number" : 302,          "balance" : 11298,          "firstname" : "Isabella",          "lastname" : "Hewitt",          "age" : 40,          "gender" : "M",          "address" : "455 Bedford Avenue",          "employer" : "Cincyr",          "email" : "isabellahewitt@cincyr.com",          "city" : "Blanford",          "state" : "IN"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "340",        "_score" : 1.0,        "_source" : {          "account_number" : 340,          "balance" : 42072,          "firstname" : "Juarez",          "lastname" : "Gutierrez",          "age" : 40,          "gender" : "F",          "address" : "802 Seba Avenue",          "employer" : "Billmed",          "email" : "juarezgutierrez@billmed.com",          "city" : "Malott",          "state" : "OH"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "485",        "_score" : 1.0,        "_source" : {          "account_number" : 485,          "balance" : 44235,          "firstname" : "Albert",          "lastname" : "Roberts",          "age" : 40,          "gender" : "M",          "address" : "385 Harman Street",          "employer" : "Stralum",          "email" : "albertroberts@stralum.com",          "city" : "Watrous",          "state" : "NM"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "666",        "_score" : 1.0,        "_source" : {          "account_number" : 666,          "balance" : 13880,          "firstname" : "Mcguire",          "lastname" : "Lloyd",          "age" : 40,          "gender" : "F",          "address" : "658 Just Court",          "employer" : "Centrexin",          "email" : "mcguirelloyd@centrexin.com",          "city" : "Warren",          "state" : "MT"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "998",        "_score" : 1.0,        "_source" : {          "account_number" : 998,          "balance" : 16869,          "firstname" : "Letha",          "lastname" : "Baker",          "age" : 40,          "gender" : "F",          "address" : "206 Llama Court",          "employer" : "Dognosis",          "email" : "lethabaker@dognosis.com",          "city" : "Dunlo",          "state" : "WV"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "432",        "_score" : 1.0,        "_source" : {          "account_number" : 432,          "balance" : 28969,          "firstname" : "Preston",          "lastname" : "Ferguson",          "age" : 40,          "gender" : "F",          "address" : "239 Greenwood Avenue",          "employer" : "Bitendrex",          "email" : "prestonferguson@bitendrex.com",          "city" : "Idledale",          "state" : "ND"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

查询全部,使用filter过滤balance处于20000至30000之间的数据

[root@localhost elasticsearch-cluster]# curl -XPOST 'localhost:9201/bank/_search?pretty' -d '> {>     "query": {>         "bool": {>             "must": {"match_all": {}},>             "filter": {>                 "range": {>                     "balance": {>                         "gte": 20000,>                         "lte": 30000>                     }>                 }>             }>         }>     }> }'{  "took" : 80,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 217,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "253",        "_score" : 1.0,        "_source" : {          "account_number" : 253,          "balance" : 20240,          "firstname" : "Melissa",          "lastname" : "Gould",          "age" : 31,          "gender" : "M",          "address" : "440 Fuller Place",          "employer" : "Buzzopia",          "email" : "melissagould@buzzopia.com",          "city" : "Lumberton",          "state" : "MD"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "400",        "_score" : 1.0,        "_source" : {          "account_number" : 400,          "balance" : 20685,          "firstname" : "Kane",          "lastname" : "King",          "age" : 21,          "gender" : "F",          "address" : "405 Cornelia Street",          "employer" : "Tri@Tribalog",          "email" : "kaneking@tri@tribalog.com",          "city" : "Gulf",          "state" : "VT"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "520",        "_score" : 1.0,        "_source" : {          "account_number" : 520,          "balance" : 27987,          "firstname" : "Brandy",          "lastname" : "Calhoun",          "age" : 32,          "gender" : "M",          "address" : "818 Harden Street",          "employer" : "Maxemia",          "email" : "brandycalhoun@maxemia.com",          "city" : "Sidman",          "state" : "OR"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "645",        "_score" : 1.0,        "_source" : {          "account_number" : 645,          "balance" : 29362,          "firstname" : "Edwina",          "lastname" : "Hutchinson",          "age" : 26,          "gender" : "F",          "address" : "892 Pacific Street",          "employer" : "Essensia",          "email" : "edwinahutchinson@essensia.com",          "city" : "Dowling",          "state" : "NE"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "734",        "_score" : 1.0,        "_source" : {          "account_number" : 734,          "balance" : 20325,          "firstname" : "Keri",          "lastname" : "Kinney",          "age" : 23,          "gender" : "M",          "address" : "490 Balfour Place",          "employer" : "Retrotex",          "email" : "kerikinney@retrotex.com",          "city" : "Salunga",          "state" : "PA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "784",        "_score" : 1.0,        "_source" : {          "account_number" : 784,          "balance" : 25291,          "firstname" : "Mabel",          "lastname" : "Thornton",          "age" : 21,          "gender" : "M",          "address" : "124 Louisiana Avenue",          "employer" : "Zolavo",          "email" : "mabelthornton@zolavo.com",          "city" : "Lynn",          "state" : "AL"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "880",        "_score" : 1.0,        "_source" : {          "account_number" : 880,          "balance" : 22575,          "firstname" : "Christian",          "lastname" : "Myers",          "age" : 35,          "gender" : "M",          "address" : "737 Crown Street",          "employer" : "Combogen",          "email" : "christianmyers@combogen.com",          "city" : "Abrams",          "state" : "OK"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "14",        "_score" : 1.0,        "_source" : {          "account_number" : 14,          "balance" : 20480,          "firstname" : "Erma",          "lastname" : "Kane",          "age" : 39,          "gender" : "F",          "address" : "661 Vista Place",          "employer" : "Stockpost",          "email" : "ermakane@stockpost.com",          "city" : "Chamizal",          "state" : "NY"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "19",        "_score" : 1.0,        "_source" : {          "account_number" : 19,          "balance" : 27894,          "firstname" : "Schwartz",          "lastname" : "Buchanan",          "age" : 28,          "gender" : "F",          "address" : "449 Mersereau Court",          "employer" : "Sybixtex",          "email" : "schwartzbuchanan@sybixtex.com",          "city" : "Greenwich",          "state" : "KS"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "204",        "_score" : 1.0,        "_source" : {          "account_number" : 204,          "balance" : 27714,          "firstname" : "Mavis",          "lastname" : "Deleon",          "age" : 39,          "gender" : "F",          "address" : "400 Waldane Court",          "employer" : "Lotron",          "email" : "mavisdeleon@lotron.com",          "city" : "Stollings",          "state" : "LA"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

使用ip地址测试

使用ip地址测试,提示不能连接,说明配置有问题,因为localhost就可以

[listen@localhost ~]$ curl '192.168.159.129:9201/bank/_search?q=*&pretty'curl: (7) Failed connect to 192.168.159.129:9201; Connection refused[listen@localhost ~]$

修改配置,可以使用ip访问

[listen@localhost ~]$ cd elasticsearch-cluster/[listen@localhost elasticsearch-cluster]$ vi elasticsearch-node1/config/elasticsearch.yml #把下面这个注释打开,修改为本机的ip地址network.host: 192.168.159.129[listen@localhost elasticsearch-cluster]$ vi elasticsearch-node2/config/elasticsearch.yml #把下面这个注释打开,修改为本机的ip地址network.host: 192.168.159.129

重启服务,然后再访问

[listen@localhost elasticsearch-cluster]$ ./elasticsearch-node1/bin/elasticsearch [2017-01-19T17:56:53,521][INFO ][o.e.n.Node               ] [listen-node1] initializing ...[2017-01-19T17:56:53,600][INFO ][o.e.e.NodeEnvironment    ] [listen-node1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.2gb], net total_space [17.6gb], spins? [unknown], types [rootfs][2017-01-19T17:56:53,600][INFO ][o.e.e.NodeEnvironment    ] [listen-node1] heap size [505.6mb], compressed ordinary object pointers [unknown][2017-01-19T17:56:53,686][INFO ][o.e.n.Node               ] [listen-node1] node name [listen-node1], node ID [HkkRtyJSTlC15ysyrsJeJg][2017-01-19T17:56:53,689][INFO ][o.e.n.Node               ] [listen-node1] version[5.1.2], pid[3278], build[c8c4c16/2017-01-11T20:18:39.146Z], OS[Linux/3.10.0-514.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14][2017-01-19T17:57:10,401][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [aggs-matrix-stats][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [ingest-common][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-expression][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-groovy][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-mustache][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-painless][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [percolator][2017-01-19T17:57:10,434][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [reindex][2017-01-19T17:57:10,435][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [transport-netty3][2017-01-19T17:57:10,435][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [transport-netty4][2017-01-19T17:57:10,435][INFO ][o.e.p.PluginsService     ] [listen-node1] no plugins loaded[2017-01-19T17:57:32,289][INFO ][o.e.n.Node               ] [listen-node1] initialized[2017-01-19T17:57:32,332][INFO ][o.e.n.Node               ] [listen-node1] starting ...[2017-01-19T17:57:34,639][INFO ][o.e.t.TransportService   ] [listen-node1] publish_address {192.168.159.129:9300}, bound_addresses {192.168.159.129:9300}[2017-01-19T17:57:34,842][INFO ][o.e.b.BootstrapCheck     ] [listen-node1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checksERROR: bootstrap checks failedmax file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

重启报错,提示虚拟内存过低,加大虚拟内存试试;最大的文件描述符过低,增加试试

#提高了vm.max_map_count的大小 [listen@localhost elasticsearch-cluster]$ su Password: [root@localhost elasticsearch-cluster]# cat /etc/sysctl.conf # sysctl settings are defined through files in# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.## Vendors settings live in /usr/lib/sysctl.d/.# To override a whole file, create a new file with the same in# /etc/sysctl.d/ and put new settings there. To override# only specific settings, add a file with a lexically later# name in /etc/sysctl.d/ and put new settings there.## For more information, see sysctl.conf(5) and sysctl.d(5).[root@localhost elasticsearch-cluster]# cp /etc/sysctl.conf /etc/sysctl.conf.bak[root@localhost elasticsearch-cluster]# vi /etc/sysctl.conf#加入以下代码vm.max_map_count = 262144[root@localhost elasticsearch-cluster]# sysctl -pvm.max_map_count = 262144[root@localhost elasticsearch-cluster]#
[root@localhost elasticsearch-cluster]# cat /etc/security/limits.conf # /etc/security/limits.conf##This file sets the resource limits for the users logged in via PAM.#It does not affect resource limits of the system services.##Also note that configuration files in /etc/security/limits.d directory,#which are read in alphabetical order, override the settings in this#file in case the domain is the same or more specific.#That means for example that setting a limit for wildcard domain here#can be overriden with a wildcard setting in a config file in the#subdirectory, but a user specific setting here can be overriden only#with a user specific setting in the subdirectory.##Each line describes a limit for a user in the form:##
##Where:#
can be:# - a user name# - a group name, with @group syntax# - the wildcard *, for default entry# - the wildcard %, can be also used with %group syntax,# for maxlogin limit##
can have the two values:# - "soft" for enforcing the soft limits# - "hard" for enforcing hard limits##
can be one of the following:# - core - limits the core file size (KB)# - data - max data size (KB)# - fsize - maximum filesize (KB)# - memlock - max locked-in-memory address space (KB)# - nofile - max number of open file descriptors# - rss - max resident set size (KB)# - stack - max stack size (KB)# - cpu - max CPU time (MIN)# - nproc - max number of processes# - as - address space limit (KB)# - maxlogins - max number of logins for this user# - maxsyslogins - max number of logins on the system# - priority - the priority to run user process with# - locks - max number of file locks the user can hold# - sigpending - max number of pending signals# - msgqueue - max memory used by POSIX message queues (bytes)# - nice - max nice priority allowed to raise to values: [-20, 19]# - rtprio - max realtime priority##
##* soft core 0#* hard rss 10000#@student hard nproc 20#@faculty soft nproc 20#@faculty hard nproc 50#ftp hard nproc 0#@student - maxlogins 4# End of file[root@localhost elasticsearch-cluster]# cp /etc/security/limits.conf /etc/security/limits.conf.bak[root@localhost elasticsearch-cluster]# vi /etc/security/limits.conf#加入以下代码* soft nofile 65536* hard nofile 65536

要重新打开窗口,不然修改的参数不起作用,重启服务试试

[listen@localhost elasticsearch-cluster]$ ./elasticsearch-node1/bin/elasticsearch[2017-01-19T18:45:42,526][INFO ][o.e.n.Node               ] [listen-node1] initializing ...[2017-01-19T18:45:42,636][INFO ][o.e.e.NodeEnvironment    ] [listen-node1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.2gb], net total_space [17.6gb], spins? [unknown], types [rootfs][2017-01-19T18:45:42,636][INFO ][o.e.e.NodeEnvironment    ] [listen-node1] heap size [505.6mb], compressed ordinary object pointers [unknown][2017-01-19T18:45:42,686][INFO ][o.e.n.Node               ] [listen-node1] node name [listen-node1], node ID [HkkRtyJSTlC15ysyrsJeJg][2017-01-19T18:45:42,688][INFO ][o.e.n.Node               ] [listen-node1] version[5.1.2], pid[5025], build[c8c4c16/2017-01-11T20:18:39.146Z], OS[Linux/3.10.0-514.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14][2017-01-19T18:45:44,953][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [aggs-matrix-stats][2017-01-19T18:45:44,953][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [ingest-common][2017-01-19T18:45:44,953][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-expression][2017-01-19T18:45:44,953][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-groovy][2017-01-19T18:45:44,953][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-mustache][2017-01-19T18:45:44,954][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-painless][2017-01-19T18:45:44,954][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [percolator][2017-01-19T18:45:44,954][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [reindex][2017-01-19T18:45:44,954][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [transport-netty3][2017-01-19T18:45:44,954][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [transport-netty4][2017-01-19T18:45:44,954][INFO ][o.e.p.PluginsService     ] [listen-node1] no plugins loaded[2017-01-19T18:45:49,078][INFO ][o.e.n.Node               ] [listen-node1] initialized[2017-01-19T18:45:49,078][INFO ][o.e.n.Node               ] [listen-node1] starting ...[2017-01-19T18:45:49,362][INFO ][o.e.t.TransportService   ] [listen-node1] publish_address {192.168.159.129:9300}, bound_addresses {192.168.159.129:9300}[2017-01-19T18:45:49,366][INFO ][o.e.b.BootstrapCheck     ] [listen-node1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks[2017-01-19T18:45:52,577][INFO ][o.e.c.s.ClusterService   ] [listen-node1] new_master {listen-node1}{HkkRtyJSTlC15ysyrsJeJg}{rVFb7pw-SHqd0daIQkxMXA}{192.168.159.129}{192.168.159.129:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[2017-01-19T18:45:52,663][INFO ][o.e.h.HttpServer         ] [listen-node1] publish_address {192.168.159.129:9201}, bound_addresses {192.168.159.129:9201}[2017-01-19T18:45:52,664][INFO ][o.e.n.Node               ] [listen-node1] started[2017-01-19T18:45:52,969][INFO ][o.e.g.GatewayService     ] [listen-node1] recovered [1] indices into cluster_state[2017-01-19T18:45:53,772][INFO ][o.e.c.r.a.AllocationService] [listen-node1] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[bank][4]] ...]).
[listen@localhost elasticsearch-cluster]$ ./elasticsearch-node2/bin/elasticsearch[2017-01-19T18:46:28,178][INFO ][o.e.n.Node               ] [listen-node2] initializing ...[2017-01-19T18:46:29,757][INFO ][o.e.e.NodeEnvironment    ] [listen-node2] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.2gb], net total_space [17.6gb], spins? [unknown], types [rootfs][2017-01-19T18:46:29,758][INFO ][o.e.e.NodeEnvironment    ] [listen-node2] heap size [505.6mb], compressed ordinary object pointers [unknown][2017-01-19T18:46:30,227][INFO ][o.e.n.Node               ] [listen-node2] node name [listen-node2], node ID [WC-gRq-HQTGwlaJfERsm9A][2017-01-19T18:46:30,353][INFO ][o.e.n.Node               ] [listen-node2] version[5.1.2], pid[5145], build[c8c4c16/2017-01-11T20:18:39.146Z], OS[Linux/3.10.0-514.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14][2017-01-19T18:46:36,148][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [aggs-matrix-stats][2017-01-19T18:46:36,154][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [ingest-common][2017-01-19T18:46:36,154][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-expression][2017-01-19T18:46:36,154][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-groovy][2017-01-19T18:46:36,155][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-mustache][2017-01-19T18:46:36,155][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-painless][2017-01-19T18:46:36,155][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [percolator][2017-01-19T18:46:36,155][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [reindex][2017-01-19T18:46:36,155][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [transport-netty3][2017-01-19T18:46:36,155][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [transport-netty4][2017-01-19T18:46:36,156][INFO ][o.e.p.PluginsService     ] [listen-node2] no plugins loaded[2017-01-19T18:46:46,889][INFO ][o.e.n.Node               ] [listen-node2] initialized[2017-01-19T18:46:46,892][INFO ][o.e.n.Node               ] [listen-node2] starting ...[2017-01-19T18:46:47,529][INFO ][o.e.t.TransportService   ] [listen-node2] publish_address {192.168.159.129:9301}, bound_addresses {192.168.159.129:9301}[2017-01-19T18:46:47,533][INFO ][o.e.b.BootstrapCheck     ] [listen-node2] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks[2017-01-19T18:46:50,819][INFO ][o.e.c.s.ClusterService   ] [listen-node2] new_master {listen-node2}{WC-gRq-HQTGwlaJfERsm9A}{heeeAGJLQ6COGmwAUIaqsQ}{192.168.159.129}{192.168.159.129:9301}, reason: zen-disco-elected-as-master ([0] nodes joined)[2017-01-19T18:46:50,895][INFO ][o.e.h.HttpServer         ] [listen-node2] publish_address {192.168.159.129:9202}, bound_addresses {192.168.159.129:9202}[2017-01-19T18:46:50,896][INFO ][o.e.n.Node               ] [listen-node2] started[2017-01-19T18:46:51,664][INFO ][o.e.g.GatewayService     ] [listen-node2] recovered [1] indices into cluster_state[2017-01-19T18:46:52,259][INFO ][o.e.c.r.a.AllocationService] [listen-node2] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[bank][2]] ...]).

测试

[root@localhost elasticsearch-cluster]# curl 'localhost:9201/bank/_search?q=*&pretty'curl: (7) Failed connect to localhost:9201; Connection refused[root@localhost elasticsearch-cluster]# [root@localhost elasticsearch-cluster]# curl '192.168.159.129:9201/bank/_search?q=*&pretty'{  "took" : 599,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 1000,    "max_score" : 1.0,    "hits" : [      {        "_index" : "bank",        "_type" : "account",        "_id" : "25",        "_score" : 1.0,        "_source" : {          "account_number" : 25,          "balance" : 40540,          "firstname" : "Virginia",          "lastname" : "Ayala",          "age" : 39,          "gender" : "F",          "address" : "171 Putnam Avenue",          "employer" : "Filodyne",          "email" : "virginiaayala@filodyne.com",          "city" : "Nicholson",          "state" : "PA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "44",        "_score" : 1.0,        "_source" : {          "account_number" : 44,          "balance" : 34487,          "firstname" : "Aurelia",          "lastname" : "Harding",          "age" : 37,          "gender" : "M",          "address" : "502 Baycliff Terrace",          "employer" : "Orbalix",          "email" : "aureliaharding@orbalix.com",          "city" : "Yardville",          "state" : "DE"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "99",        "_score" : 1.0,        "_source" : {          "account_number" : 99,          "balance" : 47159,          "firstname" : "Ratliff",          "lastname" : "Heath",          "age" : 39,          "gender" : "F",          "address" : "806 Rockwell Place",          "employer" : "Zappix",          "email" : "ratliffheath@zappix.com",          "city" : "Shaft",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "119",        "_score" : 1.0,        "_source" : {          "account_number" : 119,          "balance" : 49222,          "firstname" : "Laverne",          "lastname" : "Johnson",          "age" : 28,          "gender" : "F",          "address" : "302 Howard Place",          "employer" : "Senmei",          "email" : "lavernejohnson@senmei.com",          "city" : "Herlong",          "state" : "DC"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "126",        "_score" : 1.0,        "_source" : {          "account_number" : 126,          "balance" : 3607,          "firstname" : "Effie",          "lastname" : "Gates",          "age" : 39,          "gender" : "F",          "address" : "620 National Drive",          "employer" : "Digitalus",          "email" : "effiegates@digitalus.com",          "city" : "Blodgett",          "state" : "MD"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "145",        "_score" : 1.0,        "_source" : {          "account_number" : 145,          "balance" : 47406,          "firstname" : "Rowena",          "lastname" : "Wilkinson",          "age" : 32,          "gender" : "M",          "address" : "891 Elton Street",          "employer" : "Asimiline",          "email" : "rowenawilkinson@asimiline.com",          "city" : "Ripley",          "state" : "NH"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "183",        "_score" : 1.0,        "_source" : {          "account_number" : 183,          "balance" : 14223,          "firstname" : "Hudson",          "lastname" : "English",          "age" : 26,          "gender" : "F",          "address" : "823 Herkimer Place",          "employer" : "Xinware",          "email" : "hudsonenglish@xinware.com",          "city" : "Robbins",          "state" : "ND"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "190",        "_score" : 1.0,        "_source" : {          "account_number" : 190,          "balance" : 3150,          "firstname" : "Blake",          "lastname" : "Davidson",          "age" : 30,          "gender" : "F",          "address" : "636 Diamond Street",          "employer" : "Quantasis",          "email" : "blakedavidson@quantasis.com",          "city" : "Crumpler",          "state" : "KY"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "208",        "_score" : 1.0,        "_source" : {          "account_number" : 208,          "balance" : 40760,          "firstname" : "Garcia",          "lastname" : "Hess",          "age" : 26,          "gender" : "F",          "address" : "810 Nostrand Avenue",          "employer" : "Quiltigen",          "email" : "garciahess@quiltigen.com",          "city" : "Brooktrails",          "state" : "GA"        }      },      {        "_index" : "bank",        "_type" : "account",        "_id" : "222",        "_score" : 1.0,        "_source" : {          "account_number" : 222,          "balance" : 14764,          "firstname" : "Rachelle",          "lastname" : "Rice",          "age" : 36,          "gender" : "M",          "address" : "333 Narrows Avenue",          "employer" : "Enaut",          "email" : "rachellerice@enaut.com",          "city" : "Wright",          "state" : "AZ"        }      }    ]  }}[root@localhost elasticsearch-cluster]#

 

转载于:https://my.oschina.net/Listening/blog/828000

你可能感兴趣的文章
Android WebView 学习
查看>>
(转)从给定的文本中,查找其中最长的重复子字符串的问题
查看>>
HDU 2159
查看>>
spring batch中用到的表
查看>>
资源文件夹res/raw和assets的使用
查看>>
UINode扩展
查看>>
LINUX常用命令
查看>>
百度云盘demo
查看>>
概率论与数理统计习题
查看>>
初学structs2,简单配置
查看>>
Laravel5.0学习--01 入门
查看>>
时间戳解读
查看>>
sbin/hadoop-daemon.sh: line 165: /tmp/hadoop-hxsyl-journalnode.pid: Permission denied
查看>>
@RequestMapping 用法详解之地址映射
查看>>
254页PPT!这是一份写给NLP研究者的编程指南
查看>>
《Data Warehouse in Action》
查看>>
String 源码浅析(一)
查看>>
Spring Boot 最佳实践(三)模板引擎FreeMarker集成
查看>>
Cable:360实现的新虚拟网络架构
查看>>
Fescar 发布 0.2.3 版本,支持 Redis 和 Apollo
查看>>