public static void main(String[] args) {
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("192.168.100.103", 9300));
IndexResponse response = null;
try { <pre name="code" class="java"> response = client.prepareIndex("myindex", "users", "1")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("cust_Id", "3")
.field("is_Show", 3)
.endObject()
)
.execute()
.actionGet();
} catch (ElasticSearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(response);}
开始的时候报错如下:No Node Available
1)网络是否畅通
2)查询的参数配置是否正确<
<pre name="code" class="java"> response = client.prepareIndex("myindex", "users", "1")
.setSource(XContentFactory.jsonBuilder()
.startObject()
<span style="color:#ff0000;">.field("cust_Id", "3")
.field("is_Show", 3)</span>
.endObject()
)
.execute()
.actionGet();