1. Download the archive (http://www.elasticsearch.org/download/) and unpack it 2. Start the server Unix: bin / elasticsearch –f Windows: bin / elasticsearch.bat 3. Check the server curl -X GET http: // localhost: 9200 / If everything works, the server will return you a JSON array with some information.
$ curl -XPUT 'http: // localhost: 9200 / habrahabr / users / 1' -d ' { "firstname": "Piotr", "surname": "Petrov", "birthDate": "1981-01-01", "location": "Moscow, Russian Federation", "skills": ["PHP", "HTML", "C ++", ".NET", "JavaScript"] } '
$ curl -XPUT 'http: // localhost: 9200 / habrahabr / users / 2' -d ' { "firstname": "Ivan", "surname": "Sidorov", "birthDate": "1978-12-13", "location": "Briansk, Russian Federation", "skills": ["HTML", "Ruby", "Python"] } '
$ curl -XPUT 'http: // localhost: 9200 / habrahabr / users / 3' -d ' { "firstname": "Stepan", "surname": "Fomenko", "birthDate": "1985-06-01", "location": "Ukraine", "skills": ["HTML", "XML", "Java", "JavaScript"] } '
$ curl -XGET 'http: // localhost: 9200 / habrahabr / users / _search? q = firstname: Ivan & pretty = true'
$ curl -XGET 'http: // localhost: 9200 / habrahabr / users / _search? pretty = true' -d ' { "query": { "term": {"location": "Ukraine", "skills": "PHP"} } } '
$ curl -XGET 'http: // localhost: 9200 / habrauser / _search? q = location: Russian% 20Federation & pretty = true'
$ curl -XGET 'http: // localhost: 9200 / habrauser / _count? q = location: Russian% 20Federation & pretty = true'
<?php ini_set('max_execution_time', 36000); class userGenerator { // private $countries = array( 'Russian Federation', 'Ukraine', 'Germany', 'France', 'Lithuania', 'Latvia', 'Poland', 'Finland', 'Sweden' ); public function run($cnt) { for ($i = 0; $i < $cnt; $i++) { $query = $this->generateQuery($i); echo "generating user " . $i . " ... "; exec($query); echo "done" . PHP_EOL; } } private function generateQuery($id) { // 1960- $date = new DateTime('1960-01-01'); return 'curl -XPUT \'http://localhost:9200/habrahabr/users/' . $id . '\' -d \' { "id" : "' . $id . '", "firstname" : "' . ucfirst($this->generateWord(10)) . '", "surname" : "' . ucfirst($this->generateWord(10)) . '", "birthDate" : "' . $date->modify('+' . rand(0, 14600) . ' days')->format('Ym-d') . '", "location" : "' . $this->generateWord(10) . ', ' . $this->countries[array_rand($this->countries)] . '", "skills" : ["' . strtoupper($this->generateWord(3)) . '", "' . strtoupper($this->generateWord(4)) . '", "' . strtoupper($this->generateWord(3)) . '"] }\' '; } private function generateWord($length) { $letters = array( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); $word = ''; for ($i = 0; $i < $length; $i++) { $word .= $letters[rand(0, 25)]; } return $word; } } $generator = new userGenerator(); $generator->run(5000000); echo "complete"; ?>
curl -XGET 'http: // localhost: 9200 / habrahabr / users / _count? q = * & pretty' { "count": 5128888, "_shards": { "total": 5, "successful": 5, "failed": 0 }
time curl -XPUT 'http: // localhost: 9200 / habrahabr / users / 5128889' -d ' { "firstname": "Basil", "surname": "Fedorov", "birthDate": "1975-07-11", "location": "Riga, Latvia", "skills": ["PERL", "PYTHON", "ActionScript"] } ' {"ok": true, "_ index": "habrahabr", "_ type": "users", "_ id": "5128891", "_ version": 2} real 0m0.007s user 0m0.004s sys 0m0.000s
time curl -XGET 'http: // localhost: 9200 / habrahabr / users / _search? q = location: Riga & pretty' { "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 8.854725, "hits": [{ "_index": "habrahabr", "_type": "users", "_id": "5128891", "_score": 8.854725, "_source": { "firstname": "Basil", "surname": "Fedorov", "birthDate": "1975-07-11", "location": "Riga, Latvia", "skills": ["PERL", "PYTHON", "ActionScript"] } }] } } real 0m0.011s user 0m0.004s sys 0m0.000s
$ time curl -XGET 'http: // localhost: 9200 / habrahabr / users / _count? q = location: Germany & pretty' { "count": 570295, "_shards": { "total": 5, "successful": 5, "failed": 0 } } real 0m0.079s user 0m0.004s sys 0m0.000s
Source: https://habr.com/ru/post/122531/
All Articles