I'm using JEST
to access Elasticsearch
and so far its working fine. Now I want to manage index/type mappings from my application so I followed an example from JEST
web site but I'm getting an error as bellow.
RootObjectMapper.Builder rootObjectMapperBuilder = new RootObjectMapper.Builder("person_mapping").add(
new StringFieldMapper.Builder("lastname").store(true));
Builder builder = new DocumentMapper.Builder("indexName", null, rootObjectMapperBuilder);
The error is raised on the last line staring with new DocumentMapper.Builder ...
. Its rather something internal but not sure how to fix this.
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]
Does anyone have some working example maintaining mappings for Elasticsearch
with JEST
?
EDIT #1: Integration tests are not helping me :-(
I have looked at JEST
integration test focused on mapping here https://github.com/searchbox-io/Jest/blob/master/jest/src/test/java/io/searchbox/indices/PutMappingIntegrationTest.java#L46 and it doesnt help. I dont know where comes client()
... based on others searches it seems its something from native JAVA API and not REST
? Any idea how to use it or where client() comes from?
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);
SOLVED!
DocumentMapper.Builder
requires Settings parameter. Null doesnt work here. Settings can be created manualy like this
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);
No I can see no null pointer error.