elasticsearch 创建表for windows为什么不能创建索引

当前访客身份:游客 [
喜欢折腾分布式架构,对数字图像处理比较感兴趣,会点服务器,会点Web,会点Android,会点Hadoop。专职做架构,兼职做管理,业余做运维,一直在开发
:引用来自“林中漫步”的评论你推荐的这些书都非常...
:你推荐的这些书都非常好
:作者怎么没继续写了哈?
:引用来自“shaozhengmao”的评论请问楼主 .field...
:请问楼主 .field("analyzer","ik") .field("inde...
:引用来自“以马内利”的评论楼主,公司专门做pyt...
:楼主,公司专门做python开发的?
今日访问:11
昨日访问:52
本周访问:263
本月访问:546
所有访问:37832
Elastic Search Java Api 创建索引结构,添加索引
发表于12个月前( 16:24)&&
阅读(999)&|&评论()
0人收藏此文章,
创建TCP客户端
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress(
"localhost", 9300));
client.admin().indices().prepareCreate("pages").execute().actionGet();
创建索引结构
XContentBuilder builder=XContentFactory
.jsonBuilder()
.startObject()
&&&&.startObject("sina")
.startObject("properties")
.startObject("article_title")
.field("type", "string")
.field("store", "yes")
.field("analyzer","ik")
.field("index","analyzed")
.endObject()
.startObject("article_content")
.field("type", "string")
.field("store", "no")
.field("analyzer","ik")
.field("index","analyzed")
.endObject()
.startObject("article_url")
.field("type", "string")
.field("store", "yes")
.field("index","not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject();
PutMappingRequest mapping = Requests.putMappingRequest("pages").type("sina").source(builder);
client.admin().indices().putMapping(mapping).actionGet();
添加索引数据
IndexResponse response = client.prepareIndex("pages", "sina", null)
.setSource(jsonBuilder()
.startObject()
.field("article_title", Bytes.toString(r.getValue("article".getBytes(), "title".getBytes())))
.field("article_content", Bytes.toString(r.getValue("article".getBytes(), "content".getBytes())))
.field("article_url", Bytes.toString(r.getValue("article".getBytes(), "url".getBytes())))
.endObject()
.execute()
.actionGet();
client.close();
更多开发者职位上
1)">1)">1" ng-class="{current:{{currentPage==page}}}" ng-repeat="page in pages"><li class='page' ng-if="(endIndex<li class='page next' ng-if="(currentPage
相关文章阅读elasticsearch会自动创建很多索引么_百度知道
elasticsearch会自动创建很多索引么
、高可用。为了提供了一个优秀的用户体验、基于Apache Lucene的开源搜索与分析引擎。通过它你可以很方便地对数据进行深入挖掘.,可以随时放大与缩小搜索与分析的区间,并且这一切都是实时的,我们对Elasticsearch投入了Elasticsearch是一个高伸缩
知道智能回答机器人
根据知道用户的观点和内容总结出特定问题的答案,为知道用户提供更好的问答体验。
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁我们可以把elasticsearch当做数据库来理解:
index:索引库名称,相当于关系型数据库中的表名,一个elasticsearch集群中可以有多个索引库。
type:索引库中索引数据类型,为索引类型,是用来区分同索引库下不同类型的数据的,一个索引库下可以有多个索引类型。
id:索引库中索引数据主键,唯一。
创建json document
elasticsearch有多种创建json document的方式
1. 手写,比如
String json = &{& +
&\&user\&:\&kimchy\&,& +
&\&postDate\&:\&\&,& +
&\&message\&:\&trying out Elasticsearch\&& +
2. 使用map
Map&String, Object& json = new HashMap&String, Object&();
json.put(&user&,&kimchy&);
json.put(&postDate&,new Date());
json.put(&message&,&trying out Elasticsearch&);
3. 序列化bean
For example,use jackson
&dependency&
&groupId&com.fasterxml.jackson.core&/groupId&
&artifactId&jackson-databind&/artifactId&
&version&2.1.3&/version&
&/dependency&
然后我们可以使用jackson来序列化我们的bean
import com.fasterxml.jackson.databind.*;
// instance a json mapper
ObjectMapper mapper = new ObjectMapper(); // create once, reuse
// generate json
String json = mapper.writeValueAsString(yourbeaninstance);
Elasticsearch 提供帮助类来生成JSON.
import static mon.xcontent.XContentFactory.*;
XContentBuilder builder = jsonBuilder()
.startObject()
.field(&user&, &kimchy&)
.field(&postDate&, new Date())
.field(&message&, &trying out Elasticsearch&)
.endObject()
举个例子,比如索引名字叫blog,type是post,id为1
IndexResponse response = client.prepareIndex(&blog&, &post&, &1&)
.setSource(XContentFactory.jsonBuilder().startObject()
.field(&title&, &test&)
.field(&content&, &here is content&)
.field(&tag&, &test&)
.endObject()
).execute().actionGet();
如果我们不指定id,ES会为我们生成id,setSource方法有几种形式,可以传入json字符串,map等,差不多就是上面指出的几种形式IndexResponse返回一些信息:
// Index name
String _index = response.getIndex();
// Type name
String _type = response.getType();
// Document ID (generated or not)
String _id = response.getId();
// Version (if it&#39;s the first time you index this document, you will get: 1)
long _version = response.getVersion();
//是否创建成功
boolean isCreated = response.isCreated()
检索一条记录
在创建索引时,我们根据IndexResponse,得到了index、type和id,检索一条记录的方法很简单,它可以用来判断指定index,type,id的索引是否存在
GetResponse getResponse = client.prepareGet(&blog&, &post&,&1&)
.execute()
.actionGet();
GetResponse中常用的方法有isExists(),getSourceAsString()等,前者判断指定索引是否存在,后面用来得到返回的json。我们可以根据json反序列化得到我们要的对象
Post post = mapper.readValue(getResponse.getSourceAsString(),Post.class);
与本文相关的文章

我要回帖

更多关于 elasticsearch 重索引 的文章

 

随机推荐