1. 启动elasticsearch
su - elasticsearch
cd /appl/elasticsearch-2.1.1/
bin/elasticsearch -d -p pid(初始调试时使用:bin/elasticsearch, 关闭:kill `cat pid`)
2. curl命令
查看cluster、version:curl 'centos1:9200'
插入:curl -XPUT 'http://localhost:9200/dept/employee/1' -d '{ "empname": "emp1"}'
查看index:curl 'centos1:9200/_cat/indices?v'
查看1条内容:curl 'centos1:9200/dept/employee/1?pretty'
查看所有内容:curl 'centos1:9200/dept/employee/_search'
简易搜索:curl 'centos1:9200/dept/employee/_search?empname=emp1'
复杂搜索:curl 'centos1:9200/dept/employee/_search?pretty' -d '{"query" : {"match" : {"empname" : "emp2"}}}'
删除:curl -XDELETE 'http://172.16.1.16:9200/logstash-2016.02.*'
3.1 ES原生API连接搜索(Java,非RestFul连接而是广播)
说明:Es的集群非常简单,只要在同一个局域网内,多台服务器能互相通讯,并且cluster.name是一样的,就能自动集在一起。
su - elasticsearch
cd /appl/elasticsearch-2.1.1/
bin/elasticsearch -d -p pid(初始调试时使用:bin/elasticsearch, 关闭:kill `cat pid`)
2. curl命令
查看cluster、version:curl 'centos1:9200'
插入:curl -XPUT 'http://localhost:9200/dept/employee/1' -d '{ "empname": "emp1"}'
查看index:curl 'centos1:9200/_cat/indices?v'
查看1条内容:curl 'centos1:9200/dept/employee/1?pretty'
查看所有内容:curl 'centos1:9200/dept/employee/_search'
简易搜索:curl 'centos1:9200/dept/employee/_search?empname=emp1'
复杂搜索:curl 'centos1:9200/dept/employee/_search?pretty' -d '{"query" : {"match" : {"empname" : "emp2"}}}'
删除:curl -XDELETE 'http://172.16.1.16:9200/logstash-2016.02.*'
3.1 ES原生API连接搜索(Java,非RestFul连接而是广播)
说明:Es的集群非常简单,只要在同一个局域网内,多台服务器能互相通讯,并且cluster.name是一样的,就能自动集在一起。
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.FuzzyQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.TermsQueryBuilder;
import org.elasticsearch.index.query.WildcardQueryBuilder;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
/* Implement ElasticSearch internal Java API (broadcast)
* Refer
* http://www.tuicool.com/articles/R7RVJb
* https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html