Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
b919ee81
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b919ee81
编写于
11月 19, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Elasticsearch
上级
a6263f89
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
173 addition
and
2 deletion
+173
-2
README.md
README.md
+3
-2
pom.xml
pom.xml
+1
-0
whatsmars-elasticsearch/README.md
whatsmars-elasticsearch/README.md
+6
-0
whatsmars-elasticsearch/pom.xml
whatsmars-elasticsearch/pom.xml
+40
-0
whatsmars-elasticsearch/src/main/java/org/hongxi/whatsmars/elasticsearch/ElasticsearchDemo.java
...org/hongxi/whatsmars/elasticsearch/ElasticsearchDemo.java
+37
-0
whatsmars-elasticsearch/src/main/resources/elasticsearch.yml
whatsmars-elasticsearch/src/main/resources/elasticsearch.yml
+2
-0
whatsmars-elasticsearch/src/main/resources/log4j2-test.properties
...s-elasticsearch/src/main/resources/log4j2-test.properties
+7
-0
whatsmars-elasticsearch/src/test/java/org/hongxi/whatsmars/elasticsearch/CreateIndex.java
.../java/org/hongxi/whatsmars/elasticsearch/CreateIndex.java
+46
-0
whatsmars-elasticsearch/src/test/java/org/hongxi/whatsmars/elasticsearch/GetAPI.java
.../test/java/org/hongxi/whatsmars/elasticsearch/GetAPI.java
+31
-0
未找到文件。
README.md
浏览文件 @
b919ee81
# whatsmars
*`./mvnw clean package -Dmaven.test.skip`*
[
`java 8+`
](
http://www.oracle.com/technetwork/java/javase/downloads
)
[
`mvnrepository`
]
(http://mvn.hongxi.org)
<br>
*What's Mars?*
<br>
Java生态研究(
**Spring Boot**
🔥 +
**Redis**
🔥 +
**Dubbo**
🔥 +
**RocketMQ**
🔥)
<br>
Java生态研究(
**Spring Boot**
🔥 +
**Redis**
🔥 +
**Dubbo**
🔥 +
**RocketMQ**
🔥
+
**Elasticsearch**
🔥
)
-
[
Spring Boot
](
https://spring.io/projects/spring-boot
)
Series(Servlet, Tomcat, Spring, SpringMVC, Spring Data, Spring Boot, Spring WebFlux, Spring Cloud)
-
[
Dubbo
](
http://dubbo.apache.org/en-us/
)
/
[
《企业IT架构转型之道:阿里巴巴中台战略思想与架构实战》
](
https://book.douban.com/subject/27039508/
)
-
[
《Redis设计与实现》
](
https://e.jd.com/30189715.html
)
`e.jd.com`
-
[
《RocketMQ实战与原理解析》
](
https://book.douban.com/subject/30246992/
)
`douban.com`
-
[
《Elasticsearch技术解析与实战》
](
https://e.jd.com/30318357.html
)
`e.jd.com`
👻
[
start.spring.io
](
https://start.spring.io
)
👻
[
start.dubbo.io
](
http://start.dubbo.io
)
...
...
@@ -40,7 +41,7 @@ whatsmars-tomcat | 模拟tomcat实现,embed tomcat
-
[
x] [*Redis*
](
https://github.com/antirez/redis
)
-
[
] [*Twemproxy*
](
https://github.com/twitter/twemproxy
)
-
[
] [*Otter*
](
https://github.com/alibaba/otter
)
-
[
] [*Elasticsearch*
](
https://github.com/elastic/elasticsearch
)
-
[
x
] [*Elasticsearch*
](
https://github.com/elastic/elasticsearch
)
### Friendship links
-
[
*阿里巴巴Java开发手册*
](
https://github.com/alibaba/Alibaba-Java-Coding-Guidelines
)
📚
...
...
pom.xml
浏览文件 @
b919ee81
...
...
@@ -24,6 +24,7 @@
<module>
whatsmars-sharding-jdbc
</module>
<module>
whatsmars-earth
</module>
<module>
whatsmars-spring-boot-samples
</module>
<module>
whatsmars-elasticsearch
</module>
</modules>
<properties>
...
...
whatsmars-elasticsearch/README.md
0 → 100644
浏览文件 @
b919ee81
### Elasticsearch
1.
Download and unzip Elasticsearch https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-13
1.
Run bin/elasticsearch (or bin
\e
lasticsearch.bat on Windows)
1.
Run curl http://localhost:9200/ or Invoke-RestMethod http://localhost:9200 with PowerShell
1.
Dive into the getting started guide and video.
\ No newline at end of file
whatsmars-elasticsearch/pom.xml
0 → 100644
浏览文件 @
b919ee81
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-parent
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-elasticsearch
</artifactId>
<properties>
<elasticsearch.version>
5.6.13
</elasticsearch.version>
</properties>
<dependencies>
<!-- 用于源码阅读 -->
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<version>
${elasticsearch.version}
</version>
</dependency>
<dependency>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
transport
</artifactId>
<version>
${elasticsearch.version}
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-elasticsearch/src/main/java/org/hongxi/whatsmars/elasticsearch/ElasticsearchDemo.java
0 → 100644
浏览文件 @
b919ee81
package
org.hongxi.whatsmars.elasticsearch
;
import
org.elasticsearch.action.index.IndexResponse
;
import
org.elasticsearch.client.transport.TransportClient
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.transport.InetSocketTransportAddress
;
import
org.elasticsearch.transport.client.PreBuiltTransportClient
;
import
java.net.InetAddress
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by shenhongxi on 2018/11/19.
*/
public
class
ElasticsearchDemo
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// on startup
//此步骤添加IP,至少一个,如果设置了"client.transport.sniff"= true 一个就够了,因为添加了自动嗅探配置
TransportClient
client
=
new
PreBuiltTransportClient
(
Settings
.
EMPTY
)
.
addTransportAddress
(
new
InetSocketTransportAddress
(
InetAddress
.
getByName
(
"127.0.0.1"
),
9300
));
Map
<
String
,
Object
>
json
=
new
HashMap
<>();
json
.
put
(
"user"
,
"hongxi"
);
json
.
put
(
"postDate"
,
"2013-01-30"
);
json
.
put
(
"message"
,
"Elasticsearch Study"
);
IndexResponse
response
=
client
.
prepareIndex
(
"whatsmars"
,
"hello"
,
"1"
)
.
setSource
(
json
)
.
get
();
System
.
out
.
println
(
response
.
getResult
());
// on shutdown
client
.
close
();
}
}
whatsmars-elasticsearch/src/main/resources/elasticsearch.yml
0 → 100644
浏览文件 @
b919ee81
cluster.name
:
mars
client.transport.sniff
:
true
\ No newline at end of file
whatsmars-elasticsearch/src/main/resources/log4j2-test.properties
0 → 100644
浏览文件 @
b919ee81
appender.console.type
=
Console
appender.console.name
=
console
appender.console.layout.type
=
PatternLayout
appender.console.layout.pattern
=
[%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n
rootLogger.level
=
${sys:tests.es.logger.level:-info}
rootLogger.appenderRef.console.ref
=
console
whatsmars-elasticsearch/src/test/java/org/hongxi/whatsmars/elasticsearch/CreateIndex.java
0 → 100644
浏览文件 @
b919ee81
package
org.hongxi.whatsmars.elasticsearch
;
import
org.elasticsearch.action.index.IndexResponse
;
import
org.elasticsearch.client.transport.TransportClient
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.transport.InetSocketTransportAddress
;
import
org.elasticsearch.common.xcontent.XContentBuilder
;
import
org.elasticsearch.common.xcontent.XContentFactory
;
import
org.elasticsearch.transport.client.PreBuiltTransportClient
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.util.Date
;
/**
* Created by shenhongxi on 2018/11/19.
*/
public
class
CreateIndex
{
private
TransportClient
client
;
@Before
public
void
getClient
()
throws
Exception
{
client
=
new
PreBuiltTransportClient
(
Settings
.
EMPTY
)
.
addTransportAddress
(
new
InetSocketTransportAddress
(
InetAddress
.
getByName
(
"127.0.0.1"
),
9300
));
}
/**
* 使用ElasticSearch 帮助类
* @throws IOException
*/
@Test
public
void
CreateXContentBuilder
()
throws
IOException
{
XContentBuilder
builder
=
XContentFactory
.
jsonBuilder
()
.
startObject
()
.
field
(
"user"
,
"javahongxi"
)
.
field
(
"postDate"
,
new
Date
())
.
field
(
"message"
,
"Elasticsearch Stack Study"
)
.
endObject
();
IndexResponse
response
=
client
.
prepareIndex
(
"whatsmars"
,
"test"
,
"1"
).
setSource
(
builder
).
get
();
System
.
out
.
println
(
response
);
}
}
whatsmars-elasticsearch/src/test/java/org/hongxi/whatsmars/elasticsearch/GetAPI.java
0 → 100644
浏览文件 @
b919ee81
package
org.hongxi.whatsmars.elasticsearch
;
import
org.elasticsearch.action.get.GetResponse
;
import
org.elasticsearch.client.transport.TransportClient
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.transport.InetSocketTransportAddress
;
import
org.elasticsearch.transport.client.PreBuiltTransportClient
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.net.InetAddress
;
/**
* Created by shenhongxi on 2018/11/19.
*/
public
class
GetAPI
{
private
TransportClient
client
;
@Before
public
void
getClient
()
throws
Exception
{
client
=
new
PreBuiltTransportClient
(
Settings
.
EMPTY
)
.
addTransportAddress
(
new
InetSocketTransportAddress
(
InetAddress
.
getByName
(
"127.0.0.1"
),
9300
));
}
@Test
public
void
get
()
{
GetResponse
response
=
client
.
prepareGet
(
"whatsmars"
,
"fendodate"
,
"1"
).
get
();
System
.
out
.
println
(
response
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录