一、安装
1 2 3 |
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.11.tar.gz tar zxvf elasticsearch-0.19.11.tar.gz cd elasticsearch-0.19.11 |
二、启动
1 |
./bin/elasticsearch -f |
三、创建索引
1 |
curl -XPUT 'http://172.16.109.130:9200/blog/user/dilbert' -d '{"name":"Dilbert Brown"}' |
1 2 3 4 5 6 7 |
curl -XPUT 'http://172.16.109.130:9200/blog/post/1' -d ' { "user":"dilbert", "postDate":"2012-11-30", "body":"Search is hard, Search should be easy.", "title":"On Search" }' |
1 2 3 4 5 6 7 |
curl -XPUT 'http://172.16.109.130:9200/blog/post/2' -d ' { "user":"dilbert", "postDate":"2012-11-29", "body":"Distribution is hard, Distribution should be easy.", "title":"On distribution search" }' |
1 2 3 4 5 6 7 |
curl -XPUT 'http://172.16.109.130:9200/blog/post/3' -d ' { "user":"dilbert", "postDate":"2012-11-28", "body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat", "title":"Lorem ipsum" }' |
四、读取索引内容
1 2 3 4 |
curl -XGET 'http://172.16.109.130:9200/blog/user/dilbert?pretty=true' curl -XGET 'http://172.16.109.130:9200/blog/post/1?pretty=true' curl -XGET 'http://172.16.109.130:9200/blog/post/2?pretty=true' curl -XGET 'http://172.16.109.130:9200/blog/post/3?pretty=true' |
返回结果以JSON形式呈现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "_index" : "blog", "_type" : "post", "_id" : "1", "_version" : 1, "exists" : true, "_source" : { "user":"dilbert", "postDate":"2012-11-30", "body":"Search is hard, Search should be easy.", "title":"On Search" } } |
五、搜索
搜索用户名为dilbert的用户:
1 |
curl 'http://172.16.109.130:9200/blog/post/_search?q=user:dilbert&pretty=true' |
搜索title字段包含search但不包含distribution的数据:
1 |
curl 'http://172.16.109.130:9200/blog/post/_search?q=+title:search%20-title:distribution&pretty=true&fields=title' |
近期评论