Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

EmbeddedElastic.createIndex method throws NullPointerException #67

Open
mallim opened this issue Sep 20, 2018 · 3 comments
Open

EmbeddedElastic.createIndex method throws NullPointerException #67

mallim opened this issue Sep 20, 2018 · 3 comments

Comments

@mallim
Copy link

mallim commented Sep 20, 2018

NullPointerException at the following place when calling EmbeddedElastic.createIndex:

this.indicesDescription.getIndexSettings(indexName).ifPresent((indexSettings) -> {
	this.setIndexSettingsAsEntity(request, indexSettings);
});

For reference, I am able to do the following with high level rest client:

CreateIndexRequest request = new CreateIndexRequest("index");
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(request);
@gaczm
Copy link
Contributor

gaczm commented Sep 29, 2018

To be able to do anything with this I will need to see your embedded elasticsearch configuration and full stacktrace

@Sealdolphin
Copy link

Sealdolphin commented Jul 10, 2019

Hello, I have a similar problem.
I use Embedded ES for testing, and I am setting up the ES instance in @Before phase (I call EmbeddedElastic.start()), and for the specific test I try to create an index with EmbeddedElastic.createIndex(String) in the start of @Test phase which returns NPE.

I find this strange, because in athoner @Test I use EmbeddedElastic.index(String,String,String) to create documents and it works fine. Also note, that EmbeddedElastic.Builder.withIndex() also works fine

I insert a reference code to what I mean:

class BasicElasticSearchIndexApiTest {

    private var embeddedES : EmbeddedElastic = EmbeddedElastic.builder()
        .withElasticVersion(ESVersion)
        .withSetting(PopularProperties.CLUSTER_NAME, CLUSTER)
        .withSetting(PopularProperties.TRANSPORT_TCP_PORT, 9350)
        .withIndex(META_INDEX)
        .withStartTimeout(1000, TimeUnit.SECONDS)
        .build()

    @Before
    fun setUp() {
        embeddedES.start().recreateIndex(META_INDEX)
    }

    @Test
    fun `test which works`(context: TestContext){
        embeddedES.index(META_INDEX, META_TYPE, data.encode())
    }

    @Test
    fun `test which returns NPE`(context: TestContext){
        embeddedES.createIndex(TEST_INDEX)
    }

}

This code above is in Kotlin and contains only relevant information regarding this problem.
I also use Vert.x because I run these test asynchronously

The stacktrace was the following:

java.lang.NullPointerException
	at pl.allegro.tech.embeddedelasticsearch.ElasticRestClient.createIndex(ElasticRestClient.java:60)
	at pl.allegro.tech.embeddedelasticsearch.EmbeddedElastic.createIndex(EmbeddedElastic.java:174)
	at <...>.BasicElasticSearchIndexApiTest$test which returns NPE$2.handle(BasicESIndexApiTest.kt:255)
	at <...>.BasicElasticSearchIndexApiTest$test which returns NPE$2.handle(BasicESIndexApiTest.kt:88)
	at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:272)
	at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

Thank you for your forward help

@Sealdolphin
Copy link

Update: I think I have misread the usage and functionality.

If I understood correctly, EmbeddedElastic.createIndex() works only for indices already created during setup. As it is in the docs:

creates index with name specified during EmbeddedElastic creation; note that this index is created during EmbeddedElastic startup, you will need this method only if you deleted your index using deleteIndex method

So @mallim could it be, that the index you are trying to create is not yet created via EmbeddedElastic.builder?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants