[7.2] Unexplained Null Pointer Exception when doing explore query using certain phrases

Hi there.

I am getting a really hard to trace null pointer exception from my elastic cluster when doing explore queries with certain words eg:
Game Console: Null pointer exception
Game Consoles: Results

I am hoping someone can help me track down what exactly is causing this are both those queries are using the same hops layout. I cant get the raw json being sent to the cluster out of Spring Boot to be able to test that out in the dev console. I think that might shed some light on a potential cause of this but im not sure

Below is a stack trace if that helps anyone.

{"error":{"root_cause":[],"type":"search_phase_execution_exception","reason":"","phase":"response","grouped":true,"failed_shards":[],"caused_by":{"type":"null_pointer_exception","reason":null}},"status":500}
		at org.elasticsearch.client.RestClient$1.completed(RestClient.java:552)
		at org.elasticsearch.client.RestClient$1.completed(RestClient.java:537)
		at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:122)
		at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:181)
		at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448)
		at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338)
		at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
		at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
		at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
		at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:121)
		at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
		at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
		at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
		at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
		at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
		at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
		... 1 more
Caused by: ElasticsearchException[Elasticsearch exception [type=null_pointer_exception, reason=null]]
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:509)
	at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:420)
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:450)
	at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:616)
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:169)
	... 29 more

Can you share a bit more about your code and how you end up in such an error?

Sure thing.

	List<Vertex> elasticexplore(String term, List<Vertex> previousVertexs, QueryVertix queryVertix) throws IOException {
	GraphExploreRequest request = new GraphExploreRequest();
	request.indices(generic_metadata_one, generic_metadata_two);
	request.useSignificance(true);
	request.timeout("5000ms");
	makeQueryDefinition(request, term);
	GraphExploreResponse exploreResponse = elasticsearchRestClient.graph().explore(request, RequestOptions.DEFAULT);
	return new ArrayList<>(exploreResponse.getVertices());
}

private void makeQueryDefinition(GraphExploreRequest request, String query){
	QueryBuilder simpleQueryStringBuilder = new SimpleQueryStringBuilder(query);
	Hop generalHop = request.createNextHop(simpleQueryStringBuilder);
	List<FieldMap> fieldMap = getFieldMap();
	int size = 10;
	for (FieldMap map : fieldMap) {
		addElementsAsBothVertexAndHop(request, generalHop, size, map);
	}
}

private void addElementsAsBothVertexAndHop(GraphExploreRequest request, Hop generalHop, int size, FieldMap map) {
	createVertex(request.createNextHop(null), map, size, Collections.emptyList(), Collections.emptyList());
	createVertex(generalHop, map, size, Collections.emptyList(), Collections.emptyList());
}
private void createVertex(Hop hop, FieldMap fieldMap, int size, List<String> exclusions, List<String> inclusions){
	VertexRequest vertexRequest = hop.addVertexRequest(fieldMap.getField());
	vertexRequest.size(size);
	if(!exclusions.isEmpty() && fieldMap.isExclude()){
		exclusions.forEach(vertexRequest::addExclude);
	}
	if(!inclusions.isEmpty() && fieldMap.isInclude()){
		inclusions.forEach(x -> vertexRequest.addInclude(x, 1f));
	}
}

private List<FieldMap> getFieldMap(){
	ArrayList<FieldMap> fieldMap = new ArrayList<>();
	fieldMap.add(FieldMap.builder()
			.exclude(true)
			.include(true)
			.field("brand.keyword")
			.build());
	fieldMap.add(FieldMap.builder()
			.exclude(true)
			.include(true)
			.field("categories.keyword")
			.build());
	fieldMap.add(FieldMap.builder()
			.exclude(false)
			.include(true)
			.field("colour.keyword")
			.build());
	fieldMap.add(FieldMap.builder()
			.exclude(true)
			.include(true)
			.field("name.keyword")
			.build());
	fieldMap.add(FieldMap.builder()
			.exclude(false)
			.include(true)
			.field("price.keyword")
			.build());
	return fieldMap;
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.