updated documentation

This commit is contained in:
Mohsin Husen 2013-03-25 10:13:16 +00:00
parent 8fc70b59e0
commit 23e7a0a9b6
2 changed files with 52 additions and 19 deletions

View File

@ -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>

View File

@ -30,4 +30,53 @@ Page&lt;SampleEntity&gt; 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&lt;SampleEntity&gt; sampleEntities = new ArrayList&lt;SampleEntity&gt;();
boolean hasRecords = true;
while (hasRecords){
Page&lt;SampleEntity&gt; page = elasticsearchTemplate.scroll(scrollId, 5000L , new ResultsMapper&lt;SampleEntity&gt;() {
@Override
public Page&lt;SampleEntity&gt; mapResults(SearchResponse response) {
List&lt;SampleEntity&gt; chunk = new ArrayList&lt;SampleEntity&gt;();
for(SearchHit searchHit : response.getHits()){
if(response.getHits().getHits().length &lt;= 0) {
return null;
}
SampleEntity user = new SampleEntity();
user.setId(searchHit.getId());
user.setMessage((String)searchHit.getSource().get("message"));
chunk.add(user);
}
return new PageImpl&lt;SampleEntity&gt;(chunk);
}
});
if(page != null) {
sampleEntities.addAll(page.getContent());
hasRecords = page.hasNextPage();
}
else{
hasRecords = false;
}
}
}</programlisting>
</example>
</section>
</chapter> </chapter>