我试图让自己熟悉一个项目的弹性搜索,但我似乎无法摆脱异常。这是基本代码:
import org.elasticsearch.action.fieldstats.FieldStats;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.*;
import org.elasticsearch.node.Node;
import java.io.IOException;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
import static org.elasticsearch.node.NodeBuilder.*;
public class Testing {
public static void main(String[] args) throws IOException {
Node node = nodeBuilder().node();
Client client = node.client();
IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new FieldStats.Date())
.field("message", "trying out Elasticsearch")
.endObject()
)
.execute()
.actionGet();
}
}
这是我得到的例外:
Exception in thread "main" java.lang.IllegalStateException: path.home is not configured
at org.elasticsearch.env.Environment.<init>(Environment.java:99)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:85)
at org.elasticsearch.node.Node.<init>(Node.java:128)
我搜索了很多内容,但我无处可找到关于在何处设置此参数的答案&#34; path.home&#34;。我已经尝试在elasticsearch.yml文件中将它设置在项目../resources文件夹内部和elasticsearch的安装文件夹中,但是没有成功。
也许我有点失明,但非常感谢你的帮助。 谢谢!
答案 0 :(得分:1)
我自己解决了这个问题。事实证明,我使用的是具有此问题的ElasticSearch的BETA 2.0版。我已经切换到版本1.7.2,现在一切都很好。