下载.90.6,解压,移动弹性搜索到/ usr /共享/ elasticsearch(使用chmod 777个-R权限上centosx64 6.4),重命名集群somethingstupid和启动的服务器。
已安装插件ESHead和ESBrowser b / c Im是新的并且需要它(习惯于Solr的漂亮ui)。这样我就知道服务器也在运行。
我可以通过curl创建索引:curl -XPOST 'http://localhost:9200/testindex'
并删除它:curl -XDELETE 'http://localhost:9200/testindex'
当我尝试创建新索引并为article类型的文档建立索引并通过Java API对其进行查看时,eclipse会运行代码,在控制台中显示基本日志记录,然后关闭且没有错误。另外,在我的日志中,最新行仅显示我已开始弹性搜索,但仅此而已。就像代码甚至没有达到弹性搜索一样。运行Java api后,没有索引或文章显示。我想念什么?
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;
public class PostES {
public static void main (String args[]){
PostES p = new PostES();
p.postElasticSearch();
}
public static Map<String, Object> putJsonDocument(String title, String content, Date postDate, String author){
Map<String, Object> jsonDocument = new HashMap<String, Object>();
jsonDocument.put("title", title);
jsonDocument.put("conten", content);
jsonDocument.put("postDate", postDate);
jsonDocument.put("author", author);
return jsonDocument;
}
private void postElasticSearch(){
Node node = nodeBuilder().node();
Client client = node.client();
client.prepareIndex("testindex", "article")
.setSource(putJsonDocument("Example Title",
"This description is so important. You don't even know!",
new Date(),
"J.R."))
.execute().actionGet();
node.close();
}
}
我的资料来源:http : //java.dzone.com/articles/elasticsearch-java-api。其他所有东西,包括弹性文档,都以一种或另一种方式失败。...(对于PostES类型,未定义jsonBuilder()方法)。
根据文档,我应该能够做到这一点。但这也不起作用:
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
public class TestPostMethod2 {
public static void main(String[] args) {
Node node = nodeBuilder().local(true).node();
Client client = node.client();
String json =
"{\"user\":\"kimchy\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elastic Search\"}";
IndexResponse response = client.prepareIndex("testindex", "article")
.setSource(json)
.execute()
.actionGet();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句