Skip to content

[5.1] Returned values of runtime fields are null for every field except the last one #2727

Closed
@shahzebklp

Description

@shahzebklp

I am adding runtime fields to my NativeQuery object like this:

public void addRuntimeFieldsToQuery(NativeQuery query) {
  String field1 = "runtimeField1";
  String field2 = "runtimeField2";

  query.addRuntimeField(new RuntimeField(field1, "keyword", getScript(field1)));
  query.addRuntimeField(new RuntimeField(field2, "keyword", getScript(field2)));

  query.addFields(field1, field2);
}

When I do the query I can see in my debugger that both fields and runtimeFields lists are populated just like I expect them to be in the query. However, when I get the search result only the last field's, i.e. field2, value is non-null – the rest are null. If I change the order of the last line to be query.addFields(field2, field1), then only field1's value is non-null.

This started happening after upgrading to Spring Boot 3 and the new client libraries

import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.*;

I am also using import org.springframework.data.elasticsearch.core.ElasticsearchOperations for doing the search.
I am on Spring Boot version 3.1.0 and spring-data-elasticsearch 5.1.0.

At this point I am suspecting something in the spring api is behaving differently than what it used to in Spring Boot 2.x. I have tested this for both SB2 and SB3 and Elasticsearch 7.17.7 and 8.10.3, and this issue is only showing up in SB3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions