Skip to content

Build IndexQuery with source and version, get NullPointerException #1893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
backbp opened this issue Aug 5, 2021 · 0 comments · Fixed by #1894
Closed

Build IndexQuery with source and version, get NullPointerException #1893

backbp opened this issue Aug 5, 2021 · 0 comments · Fixed by #1894
Assignees
Labels
type: bug A general bug

Comments

@backbp
Copy link

backbp commented Aug 5, 2021

When build indexQuery withSource and withVersion, but with out Object, get NullPointerException in org.springframework.data.elasticsearch.core.RequestFactory indexRequestBuilder()

where query.getObject() == null and run query.getObject().getClass() when query.getVersion() != null

if (query.getObject() != null) {
	String id = StringUtils.isEmpty(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId();
	// If we have a query id and a document id, do not ask ES to generate one.
	if (id != null) {
		indexRequestBuilder = client.prepareIndex(indexName, type, id);
	} else {
		indexRequestBuilder = client.prepareIndex(indexName, type);
	}
	indexRequestBuilder.setSource(elasticsearchConverter.mapObject(query.getObject()).toJson(),
			Requests.INDEX_CONTENT_TYPE);
} else if (query.getSource() != null) {
	indexRequestBuilder = client.prepareIndex(indexName, type, query.getId()).setSource(query.getSource(),
			Requests.INDEX_CONTENT_TYPE);
} else {
	throw new InvalidDataAccessApiUsageException(
			"object or source is null, failed to index the document [id: " + query.getId() + ']');
}

if (query.getVersion() != null) {
	indexRequestBuilder.setVersion(query.getVersion());
	VersionType versionType = retrieveVersionTypeFromPersistentEntity(query.getObject().getClass());
	indexRequestBuilder.setVersionType(versionType);
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 5, 2021
@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 6, 2021
@sothawo sothawo self-assigned this Aug 6, 2021
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Aug 6, 2021
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Aug 6, 2021
@sothawo sothawo closed this as completed in 9394030 Aug 6, 2021
sothawo added a commit that referenced this issue Aug 6, 2021
@sothawo sothawo linked a pull request Aug 6, 2021 that will close this issue
sothawo added a commit that referenced this issue Aug 6, 2021
Original Pull Request #1894
Closes #1893

(cherry picked from commit 36b449c)
sothawo added a commit that referenced this issue Aug 6, 2021
Original Pull Request #1894
Closes #1893

(cherry picked from commit 36b449c)
(cherry picked from commit c0781ef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants