`
wbj0110
  • 浏览: 1552146 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

3.分布式搜索elasticsearch java API 之------索引数据

阅读更多

es索引数据非常方便,只需构建个json格式的数据提交到es就行,下面是个java api的例子

[java] view plaincopy
  1. XContentBuilder doc = jsonBuilder()  
  2.       .startObject()       
  3.           .field("title""this is a title!")  
  4.           .field("description""descript what?")   
  5.           .field("price"100)  
  6.           .field("onSale"true)  
  7.           .field("type"1)  
  8.           .field("createDate"new Date())                            
  9.      .endObject();  
  10. client.prepareIndex("productIndex","productType").setSource(doc).execute().actionGet();  

其中productIndex为索引库名,一个es集群中可以有多个索引库。productType为索引类型,是用来区分同索引库下不同类型的数据的,一个索引库下可以有多个索引类型。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics