mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 12:02:10 +00:00
updated documentation
This commit is contained in:
parent
8fc70b59e0
commit
23e7a0a9b6
@ -448,24 +448,8 @@ public void setRepository(ProductRepository repository) {
|
|||||||
}</programlisting>
|
}</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</section>
|
</section>
|
||||||
<!--<section id="elasticsearch.query-methods.named-queries">-->
|
|
||||||
<!--<title>Using NamedQueries</title>-->
|
|
||||||
<!--<para>-->
|
|
||||||
<!--Named queries can be kept in a properties file and wired to the-->
|
|
||||||
<!--accroding method. Please mind the naming convention described in-->
|
|
||||||
<!--<xref linkend="repositories.query-methods.query-lookup-strategies" />-->
|
|
||||||
<!--or use-->
|
|
||||||
<!--<interfacename>@Query</interfacename>-->
|
|
||||||
<!--.-->
|
|
||||||
<!--</para>-->
|
|
||||||
<!--<example>-->
|
|
||||||
<!--<title>-->
|
|
||||||
<!--Declare named query in properites file-->
|
|
||||||
<!--</title>-->
|
|
||||||
<!--<programlisting></programlisting>-->
|
|
||||||
<!--<programlisting language="java">-->
|
|
||||||
<!--}</programlisting>-->
|
|
||||||
<!--</example>-->
|
|
||||||
<!--</section>-->
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
</chapter>
|
</chapter>
|
@ -30,4 +30,53 @@ Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(sea
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</section>
|
</section>
|
||||||
|
<section id="elasticsearch.scan.and.scroll">
|
||||||
|
<title>Using Scan And Scroll For Big Result Set</title>
|
||||||
|
<para>
|
||||||
|
Elasticsearch has scan and scroll feature for getting big result set in chunks.
|
||||||
|
<interfacename>ElasticsearchTemplate</interfacename>
|
||||||
|
has scan and scroll methods that can be used as below.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>
|
||||||
|
Using Scan and Scroll
|
||||||
|
</title>
|
||||||
|
<programlisting language="java">
|
||||||
|
SearchQuery searchQuery = new SearchQuery();
|
||||||
|
searchQuery.addIndices("test-index");
|
||||||
|
searchQuery.addTypes("test-type");
|
||||||
|
searchQuery.setElasticsearchQuery(matchAllQuery());
|
||||||
|
searchQuery.setPageable(new PageRequest(0,1));
|
||||||
|
String scrollId = elasticsearchTemplate.scan(searchQuery,1000,false);
|
||||||
|
List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>();
|
||||||
|
boolean hasRecords = true;
|
||||||
|
while (hasRecords){
|
||||||
|
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L , new ResultsMapper<SampleEntity>() {
|
||||||
|
@Override
|
||||||
|
public Page<SampleEntity> mapResults(SearchResponse response) {
|
||||||
|
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||||
|
for(SearchHit searchHit : response.getHits()){
|
||||||
|
if(response.getHits().getHits().length <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SampleEntity user = new SampleEntity();
|
||||||
|
user.setId(searchHit.getId());
|
||||||
|
user.setMessage((String)searchHit.getSource().get("message"));
|
||||||
|
chunk.add(user);
|
||||||
|
}
|
||||||
|
return new PageImpl<SampleEntity>(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
if(page != null) {
|
||||||
|
sampleEntities.addAll(page.getContent());
|
||||||
|
hasRecords = page.hasNextPage();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
hasRecords = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}</programlisting>
|
||||||
|
</example>
|
||||||
|
</section>
|
||||||
</chapter>
|
</chapter>
|
Loading…
x
Reference in New Issue
Block a user