设为首页 加入收藏

TOP

window7下的ElasticSearch的安装和学习(一)
2019-05-11 00:43:49 】 浏览:75
Tags:window7 ElasticSearch 安装 学习
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/se7en_q/article/details/46930771
一、下载elasticSearch(目前为止的最新版本是1.7,但是才出不久不稳地还是安分的用1.6.1吧!)

https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.6.1.zip

二、将下载的文件进行解压的路径为:D:\搜狗高速下载\elasticsearch-1.4.2

到该文件的bin 目录下 ,双击elasticsearch.bat

在浏览器下输入:http://localhost:9200pretty

如果status为200则表示打开成功。

三、接下来可以安装marvel,还是在bin目录下

按住shift键右击空白的地方-->点击在此处打开的命令窗口-->输入:plugin-ielasticsearch/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里面测一测,看值是否插入。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Project01---GraphX根据边构建连.. 下一篇(3.1.2)Servlet生命周期

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目