Hi,
I'm using REST High Level Client in v7.5
I'm getting error when I tried to update all document by UpdateByQueryRequest.
Error message : cannot write xcontent for unknown value of type class entity.Navigation
Belows are my sample code.
private static void updateByQueryForNavigation() throws IOException {
Navigation navi1 = new Navigation(Arrays.asList("1", "2", "3"), "2020-01-01T10:00:00", "2020-01-01T10:00:00");
Navigation navi2 = new Navigation(Arrays.asList("4", "5", "6"), "2020-01-01T10:00:00", "2020-01-01T10:00:00");
List<Navigation> naviList = new ArrayList<>();
naviList.add(navi1);
naviList.add(navi2);
Map<String, Object> params = new HashMap<>();
params.put("navigation", naviList);
String source = "ctx._source.navigation = params.navigation";
UpdateByQueryRequest request = new UpdateByQueryRequest("test");
request.setScript(new Script(ScriptType.INLINE, "painless", source, params));
client.updateByQuery(request, RequestOptions.DEFAULT);
}
=========================================================================
package entity;
import java.io.Serializable;
import java.util.List;
public class Navigation implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> navigationCode;
private String startDate;
private String endDate;
public Navigation(List<String> navigationCode, String startDate, String endDate) {
this.navigationCode = navigationCode;
this.startDate = startDate;
this.endDate = endDate;
}
public Navigation() {
}
public List<String> getNavigationCode() {
return navigationCode;
}
public String getStartDate() {
return startDate;
}
public String getEndDate() {
return endDate;
}
}
If I convert naviList to json then set it into param, error doesn't happen but result is not what I expected. Json string is directly insert into document. My expectation is naviList is inserted as nested array object.
Before
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "test name"
}
}
]
After(expectation)
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"navigation" : [
{
"endDate" : "2020-01-01T10:00:00",
"navigationCode" : [
"1",
"2",
"3"
],
"startDate" : "2020-01-01T10:00:00"
},
{
"endDate" : "2020-01-01T10:00:00",
"navigationCode" : [
"4",
"5",
"6"
],
"startDate" : "2020-01-01T10:00:00"
}
],
"name" : "test name"
}
}
]
Below request works as expected. I just would like to achieve same output by Java High Level client.
POST /test/_update_by_query
{
"script" : {
"source" : "ctx._source.navigation = params.navigation",
"params" : {
"navigation" : [{"navigationCode":["1","2","3"],"startDate":"2020-01-01T10:00:00","endDate":"2020-01-01T10:00:00"},{"navigationCode":["4","5","6"],"startDate":"2020-01-01T10:00:00","endDate":"2020-01-01T10:00:00"}]
},
"lang" : "painless"
}
}
I already checked below discussion but couldn't find answer.
Thank you in advance.
Tsubasa