使用 Java API 在 Elasticsearch 中创建索引并给出 NoClassFoundException
Creating Index in Elasticsearch using Java API giving NoClassFoundException
我正在尝试使用 Java API 创建基于节点的客户端并索引 JSON 文档。这是代码:
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;
public class Els {
public static void main (String args[]){
Els p = new Els();
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("content", content);
jsonDocument.put("postDate", postDate);
jsonDocument.put("author", author);
return jsonDocument;
}
Node node = nodeBuilder().clusterName("elasticsearch").client(true).node();
Client client = node.client();
private void postElasticSearch(){
client.prepareIndex("testindex", "article")
.setSource(putJsonDocument("Example Title",
"This description is so important. You dont even know!",
new Date(),
"J.R."))
.execute().actionGet();
node.close();}
}
但是当我运行这段代码时,它给出了
java.lang.NoClassDefFoundError:org/apache/lucene/analysis/miscellaneous/PatternAnalyzer
谁能建议我做错了什么。
ES 1.5.2 使用 Lucene 4.10.4。从 here 获取您需要的罐子。请注意,您可能不仅需要 lucene-core
,还需要其他人。只需浏览 Maven 存储库并查找其他 jar,但所有版本都应该是 4.10.4。
我正在尝试使用 Java API 创建基于节点的客户端并索引 JSON 文档。这是代码:
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;
public class Els {
public static void main (String args[]){
Els p = new Els();
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("content", content);
jsonDocument.put("postDate", postDate);
jsonDocument.put("author", author);
return jsonDocument;
}
Node node = nodeBuilder().clusterName("elasticsearch").client(true).node();
Client client = node.client();
private void postElasticSearch(){
client.prepareIndex("testindex", "article")
.setSource(putJsonDocument("Example Title",
"This description is so important. You dont even know!",
new Date(),
"J.R."))
.execute().actionGet();
node.close();}
}
但是当我运行这段代码时,它给出了
java.lang.NoClassDefFoundError:org/apache/lucene/analysis/miscellaneous/PatternAnalyzer
谁能建议我做错了什么。
ES 1.5.2 使用 Lucene 4.10.4。从 here 获取您需要的罐子。请注意,您可能不仅需要 lucene-core
,还需要其他人。只需浏览 Maven 存储库并查找其他 jar,但所有版本都应该是 4.10.4。