Skip to content

Instantly share code, notes, and snippets.

View JTaurus19's full-sized avatar

Ivan Tim JTaurus19

View GitHub Profile
// POST http://localhost:9200/index_name/_search
{
"size": 100,
"query": {
"bool": {
...
}
},
"pit": {
"id": "46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA==",
curl --request POST 'http://localhost:9200/index_name/_pit' \
--header 'Content-Type: application/json' \
--data-raw '{
"id" : "46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA=="
}'
curl --request POST 'http://localhost:9200/index_name/_pit?keep_alive=10m'
// POST http://localhost:9200/index_name/_search
{
"size": 100,
"query": {
"bool": {
...
}
},
"sort": [
{
{
...,
"sort": [123432415, "b6bcaa43-49aa-47be-8d4d-8f886db0c49b"]
}
// POST http://localhost:9200/index_name/_search
{
"size": 100,
"query": {
"bool": {
...
}
},
"sort": [{
"businessFieldForSorting": {
import org.json.JSONObject;
import io.searchbox.client.JestClient;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.EntityMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.searchbox.core.SearchResult;
...
public void searchDocumentsWithSearchAfter() {
String businessSortMarker = null;
String tiebreakerSortMarker = null;
while (true) {
var page = searchAfter("businessFieldForSorting", "DESC", businessSortMarker, tiebreakerSortMarker);
var content = page.getContent();
if (content.isEmpty()) {
import org.springframework.data.elasticsearch.core.ScrolledPage;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
...
@Autowired
private JestElasticsearchTemplate jestTemplate;
//how long Elasticsearch should retain the search context for the request
private static final int SCROLL_TIMEOUT = 100;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.elasticsearch.index.query.BoolQueryBuilder;
import com.github.vanroy.springdata.jest.JestElasticsearchTemplate;
...