Ich benutze elasticsearch mit Java-API, um Daten mit dem Scroll-Ansatz zu erhalten, und da ich eine Menge Daten habe ich versuche, die Daten per scrollId mit mehreren und nachfolgenden Anfragen zu paginieren.Erhalten Sie elasticsearch Daten durch scrollId in verschiedenen Anfragen
Beispiel:
Statt: POST http://localhost:8080/country
diese Rückkehr:
[
{
scrollId: abc,
data: [{country: brazil}, {country: argentina}]
},
{
scrollId: def,
data: [{country: france}, {country: germany}]
}
]
Ich mag würde verwenden: POST http://localhost:8080/country?paged=true
Mit dem ersten scrollId bei der Antwort:
{
nextScrollId: abc
}
Dann kann ich einige Anfragen durchführen, während nextScrollId
vorhanden:
POST http://localhost:8080/country?scrollId=abc
Rückkehr:
{
nextScrollId: def,
data: [{country: brazil}, {country: argentina}] //data from the "abc" scrollId
}
Dann: POST http://.../data?scrollId=def
Rückkehr:
Derzeit bin ich mit diesem Stück Code:
SearchResponse scrollResponse = elastic.getDataFromElasticSearch();
boolean hasNext = true;
String scrollId = request.getScrollId();
CountryResponse countryResponse = new CountryResponse();
do {
if (scrollResponse.getScrollId().equals(scrollId)) {
scrollResponse = client.prepareSearchScroll(scrollId)
.setScroll(TimeValue.timeValueMinutes(1))
.execute()
.actionGet();
//here i get the data from scrollResponse.getHits().getHits()
//and format it to that nextScrollId | data structure
countryResponse.addCountriesFromElasticSearchResponse(scrollResponse);
} else {
hasNext = false;
}
} while (hasNext == true);
countryResponse.setNextScrollId(scrollResponse.getScrollId());
return countryResponse;
Damit kann ich die nächste scrollId richtig zurück.
Die Sache hier ist, dass wenn ich versuche, um die Daten zu erhalten, die Schriftrolle mit dem nextScrollId Vorbereitung, ich in der Antwort keine Daten einsehen.
Ist das möglich?