0

Is this the most efficient way to retrieve only ids from ElasticSearch?

requestBuilder.setQuery(queryBuilder);
    requestBuilder.setFrom(start);
    requestBuilder.setSize(limit);
    requestBuilder.setFetchSource(false);

    SearchResponse response = requestBuilder.execute().actionGet();

    SearchHit[] hits = response.getHits().getHits();
    List<Long> refugeeIds = new ArrayList<>();
    for (SearchHit hit : hits) {
        if (hit.getId() != null) {
            refugeeIds.add(Long.parseLong(hit.getId().toString()));
        }
    }

1 Answer 1

1

That should be the best way. You don't return the _source and ES will only return the _type, _index, _score and _id.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.