我正在使用JEST
访问Elasticsearch
,到目前为止它工作正常。现在我想从我的应用程序管理索引/类型映射,所以我按照JEST
网站上的一个示例进行操作,但我收到如下错误。
RootObjectMapper.Builder rootObjectMapperBuilder = new RootObjectMapper.Builder("person_mapping").add(
new StringFieldMapper.Builder("lastname").store(true));
Builder builder = new DocumentMapper.Builder("indexName", null, rootObjectMapperBuilder);
在以 .开头的最后一行引发错误new DocumentMapper.Builder ...
。它相当内部但不知道如何解决这个问题。
java.lang.NullPointerException: null
at org.elasticsearch.Version.indexCreated(Version.java:481) ~[elasticsearch-1.7.2.jar:na]
at org.elasticsearch.index.mapper.core.NumberFieldMapper.<init>(NumberFieldMapper.java:206) ~[elasticsearch-1.7.2.jar:na]
at org.elasticsearch.index.mapper.core.IntegerFieldMapper.<init>(IntegerFieldMapper.java:132) ~[elasticsearch-1.7.2.jar:na]
at org.elasticsearch.index.mapper.internal.SizeFieldMapper.<init>(SizeFieldMapper.java:104) ~[elasticsearch-1.7.2.jar:na]
at org.elasticsearch.index.mapper.internal.SizeFieldMapper.<init>(SizeFieldMapper.java:99) ~[elasticsearch-1.7.2.jar:na]
at org.elasticsearch.index.mapper.DocumentMapper$Builder.<init>(DocumentMapper.java:182) ~[elasticsearch-1.7.2.jar:na]
有没有人有一些维护映射的工作示例Elasticsearch
with JEST
?
编辑#1:集成测试对我没有帮助:-(
我已经查看了JEST
专注于映射的集成测试https://github.com/searchbox-io/Jest/blob/master/jest/src/test/java/io/searchbox/indices/PutMappingIntegrationTest.java#L46它没有帮助。我不知道从哪里来client()
……根据其他搜索,它似乎来自本机 JAVA API,而不是REST
?知道如何使用它或 client() 来自哪里吗?
GetSettingsResponse getSettingsResponse =
client().admin().indices().getSettings(new GetSettingsRequest().indices(INDEX_NAME)).actionGet();
DocumentMapper documentMapper = new DocumentMapper
.Builder(INDEX_NAME, getSettingsResponse.getIndexToSettings().get(INDEX_NAME), rootObjectMapperBuilder).build(null);
解决了!
DocumentMapper.Builder
需要设置参数。Null 在这里不起作用。可以像这样手动创建设置
Settings indexSettings = ImmutableSettings.settingsBuilder()
.put("number_of_shards", 1)
.put("number_of_replicas", 1)
.put("index.version.created",99999)
.build();
Builder builder = new DocumentMapper.Builder("indexName",indexSettings, rootObjectMapperBuilder);
不,我看不到空指针错误。