使用JEST进行索引/类型映射会引发内部错误

时间:2015-10-19 06:59:08

标签: elasticsearch jest

我使用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]

有没有人有一些工作示例维护ElasticsearchJEST的映射?

编辑#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);

不,我看不到空指针错误。

0 个答案:

没有答案