1

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.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
David Marko
  • 2,477
  • 3
  • 27
  • 58
  • See the [integration test](https://github.com/searchbox-io/Jest/blob/master/jest/src/test/java/io/searchbox/indices/PutMappingIntegrationTest.java#L46) for example. – Cihan Keser Oct 20 '15 at 06:19
  • Tried integration tests already but it doesnt help. See my edit in the former post. – David Marko Oct 20 '15 at 11:59
  • The `client()` and `GetSettingsResponse` has nothing to do with what you are asking, they are just there for test purposes. The test case shows a complete example of putting a mapping using the `DocumentMapper.Builder`. – Cihan Keser Oct 20 '15 at 12:05
  • I know I'm just hacking something here and there. The 2 code lines from the beginning of my post are completely standalone and still raises the null pointer which comes from `Builder builder = new DocumentMapper.Builder("netnotes", null, rootObjectMapperBuilder);` – David Marko Oct 20 '15 at 12:22

0 Answers0