分布式搜索elasticsearch java API 之(三)

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

      XContentBuilder doc = jsonBuilder()            .startObject()                     .field("title", "this is a title!")                .field("description", "descript what?")                 .field("price", 100)                .field("onSale", true)                .field("type", 1)                .field("createDate", new Date())                                     .endObject();      client.prepareIndex("productIndex","productType").setSource(doc).execute().actionGet();

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

还有不愿面对失败的尴尬。曾经怀有远大理想,拥有完美的憧憬。

分布式搜索elasticsearch java API 之(三)

相关文章:

你感兴趣的文章:

标签云: