public static void main(String[] args) throws IOException {
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "foxzen")
.put("node.name", "yu").build();
Client client = new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9200));
// XXX is my server's ip address
IndexResponse response = client.prepareIndex("twitter", "tweet")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("productId", "1")
.field("productName", "XXX").endObject()).execute().actionGet();
System.out.println(response.getIndex());
System.out.println(response.getType());
System.out.println(response.getVersion());
client.close();
}
我從我的計算機上訪問服務器節點ElasticSearch的Java API:NoNodeAvailableException:無
curl -get http://XXX.XXX.XXX.XXX:9200/
得到這個
{
"status" : 200,
"name" : "yu",
"version" : {
"number" : "1.1.0",
"build_hash" : "2181e113dea80b4a9e31e58e9686658a2d46e363",
"build_timestamp" : "2014-03-25T15:59:51Z",
"build_snapshot" : false,
"lucene_version" : "4.7"
},
"tagline" : "You Know, for Search"
}
爲什麼使用Java API的出現錯誤?
EDIT
有一種elasticsearch.yml
################################### Cluster ###################################
# Cluster name identifies your cluster for auto-discovery. If you're running
# multiple clusters on the same network, make sure you're using unique names.
#
cluster.name: foxzen
#################################### Node #####################################
# Node names are generated dynamically on startup, so you're relieved
# from configuring them manually. You can tie this node to a specific name:
#
node.name: yu
ElasticSearch Java API版本爲0.19.9。我不知道如何檢查ElasticSearch服務器的版本 – Joe
您可以檢查服務器上的安裝目錄,只需查看安裝目錄lib文件夾並查看elasticsearch jar的版本。可能有一種方法可以通過curl來獲取版本,但是我無法將它想到我的頭頂(如果我可以的話,我不會相信它能夠在舊版本上工作)。 – hudsonb
您的服務器正在運行Elasticsearch 1.1.0版(它是'「number」:「1.1.0」'條目),您在問題中發佈的curl請求的響應中。 –