https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.6.1.zip
二、将下载的文件进行解压的路径为:D:\搜狗高速下载\elasticsearch-1.4.2
到该文件的bin 目录下 ,双击elasticsearch.bat
在浏览器下输入:http://localhost:9200?pretty
如果status为200则表示打开成功。
三、接下来可以安装marvel,还是在bin目录下
按住shift键右击空白的地方-->点击在此处打开的命令窗口-->输入:plugin -i elasticsearch/marvel/latest
等待它的安装之后在浏览器上输入:http://localhost:9200/_plugin/marvel/sense/index.html,如果出现以下的窗口就表示安装成功了。
四、接下来是将这东西如何和java进行整合了:
1、创建一个maven项目导入jar包
(如果对maven 不懂得安装的可以到这里:http://blog.csdn.net/se7en_q/article/details/46791323)
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.6.0</version>
</dependency>
2、在src/main/java下创建一个类ClientEL代码如下:
import java.io.IOException;
import java.util.Date;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
public class ClientEl {
public static void main(String[] args) throws ElasticsearchException, IOException {
/*用node的方式建立client*/
/*Node node=nodeBuilder().client(true).node();
Client client=node.client();*/
/*用transportClient的方式建立client,这个方式建立可以对多个的cludename进行操作,
如果是对多个的话那就要设计到cludename的命名的问题了*/
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));
/*这个是添加索引和数据的操作*/
/*IndexResponse response = client.prepareIndex("twitter", "tweet", "2")
.setSource(jsonBuilder()
.startObject()
.field("user", "se7en_q")
.field("postDate", new Date())
.field("message", "trying out Elasticsearch")
.endObject()
)
.execute()
.actionGet();
System.out.println(response.getId());*/
/*这是查询索引的操作*/
GetResponse response = client.prepareGet("twitter", "tweet", "2")
.execute()
.actionGet();
System.out.println(response.getSourceAsString());
/*如果用的是transport来建立client的关闭*/
client.close();
/*如果用的是node建立client的关闭*/
// node.close();
}
}
3、注意:如果你在对maven-clear操作遇到-Dmaven.multiModuleProjectDirectory的相关的错误时,只要在
windows-perfect-JAVA点击jdk-edit 添加这个就好了-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME
其中MAVEN_HOME是系统环境变量中maven的安装路径。
当你插入成功时记得换到marvel里面测一测,看值是否插入。