How to sort by _doc using Elasticsearch Java Client


Garnersham Lavin

I want to loop through the entire elasticsearch index/type. I am using scrolling in java client as below

SearchResponse scrollResp = client.prepareSearch(test)
        .setSearchType(SearchType.SCAN)
        .setScroll(new TimeValue(60000))
        .setQuery(qb)
        .setSize(100).execute().actionGet();

As suggested in the documentation in the link .

"The scroll request has optimizations to make it faster when the sort order is _doc. This is the most efficient option if you want to iterate through all documents regardless of order"

"sort": [
    "_doc"
  ]

How can I set the sort order to "_doc" in the Java client code above?

Richard

use this:

SearchResponse scrollResp = elasticsearchTemplate.client.prepareSearch(test)
            .setSearchType(SearchType.SCAN)
            .setScroll(new TimeValue(60000))
            .setQuery(qb).addSort("_doc" , SortOrder.ASC)
            .setSize(100).execute().actionGet();

Related


How to query ElasticSearch using Java client?

Jason: The site only contains JSON documents, no Java client. Should I perform some kind of mapping? For example geolocation query : http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-range-filter.html How can I write such a query using the Ja

How to query ElasticSearch using Java client?

Jason: The site only contains JSON documents, no Java client. Should I perform some kind of mapping? For example geolocation query : http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-range-filter.html How can I write such a query using the Ja

How to query ElasticSearch using Java client?

Jason: The site only contains JSON documents, no Java client. Should I perform some kind of mapping? For example geolocation query : http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-range-filter.html How can I write such a query using the Ja

How to connect to ElasticSearch using Java transport client?

Manolis Karamanis I am following ElasticSearch documentation on Java Client. I have ElasticSearch started and can interact with it using the Rest API. I want to use a Java client, so far I have a body like this: public class TestElastic { public static void m

How to sort by date using ElasticSearch

Glines mom I have a datefield indexed as follows: { "properties": { "productCreationDate": { "format": "YYYY-MM-dd'T'HH:mm:ssXXX", "type": "date" }, } } When I perform the search this way: { "size": 5, "from": 0, "sort": [ {

How to sort by date using ElasticSearch

Glines mom I have a datefield indexed as follows: { "properties": { "productCreationDate": { "format": "YYYY-MM-dd'T'HH:mm:ssXXX", "type": "date" }, } } When I perform the search this way: { "size": 5, "from": 0, "sort": [ {

How to sort by date using ElasticSearch

Glines mom I have a datefield indexed as follows: { "properties": { "productCreationDate": { "format": "YYYY-MM-dd'T'HH:mm:ssXXX", "type": "date" }, } } When I perform the search this way: { "size": 5, "from": 0, "sort": [ {

How to sort by date using ElasticSearch

Glines mom I have a datefield indexed as follows: { "properties": { "productCreationDate": { "format": "YYYY-MM-dd'T'HH:mm:ssXXX", "type": "date" }, } } When I perform the search this way: { "size": 5, "from": 0, "sort": [ {

How to sort by date using ElasticSearch

Glines mom I have a datefield indexed as follows: { "properties": { "productCreationDate": { "format": "YYYY-MM-dd'T'HH:mm:ssXXX", "type": "date" }, } } When I perform the search this way: { "size": 5, "from": 0, "sort": [ {

How to split .doc into several .doc using JAVA POI?

flying bat I am POIreading .doca file and I want to select some content to form a new .docfile. Specifically, is it possible to write the contents of a "paragraph" in a "range" to a new file? Thank you. HWPFDocument doc = new HWPFDocument(fs); Range range = do

How to split .doc into several .doc using JAVA POI?

flying bat I am POIreading .doca file and I want to select some content to form a new .docfile. Specifically, is it possible to write the contents of a "paragraph" in a "range" to a new file? Thank you. HWPFDocument doc = new HWPFDocument(fs); Range range = do

Elasticsearch find all indexes using Java client

Mike Rylander: Is there a way to get a list of indexes in Elasticsearch using the Java client? I've been able to find examples of doing this with Marvel/Sense, but can't seem to find any examples of doing it with the Java client. value: It's definitely possibl

Elasticsearch find all indexes using Java client

Mike Rylander: Is there a way to get a list of indexes in Elasticsearch using the Java client? I've been able to find examples of doing this with Marvel/Sense, but can't seem to find any examples of doing it with the Java client. value: It's definitely possibl

Using the ElasticSearch Java Client API via a plugin

Zanona I'm wondering if it's possible to make the ES 1.3.1 plugin run the Client API so that I can perform ES searches along my ElasticSearch plugin? I tried the following code: package org.elasticsearch.plugin.example; import org.elasticsearch.common.collect

Using the ElasticSearch Java Client API via a plugin

Zanona I'm wondering if it's possible to make the ES 1.3.1 plugin run the Client API so that I can perform ES searches along my ElasticSearch plugin? I tried the following code: package org.elasticsearch.plugin.example; import org.elasticsearch.common.collect

Elasticsearch find all indexes using Java client

Mike Rylander: Is there a way to get a list of indexes in Elasticsearch using the Java client? I've been able to find examples of doing this with Marvel/Sense, but can't seem to find any examples of doing it with the Java client. value: It's definitely possibl

Using the ElasticSearch Java Client API via a plugin

Zanona I'm wondering if it's possible to make the ES 1.3.1 plugin run the Client API so that I can perform ES searches along my ElasticSearch plugin? I tried the following code: package org.elasticsearch.plugin.example; import org.elasticsearch.common.collect

Elasticsearch: scan search vs sort by _doc

Facebook Facebook logo Sign up for Facebook to connect with Osama Azzam According to breaking changes in 2.1 : Search changes : This scansearch type is deprecated. Now, you can get all the benefits of this type of search by doing a request to sort the document

How to sort an ElasticSearch index using a field in an array?

Isuru Pathirana I need to sort documents in elastic index using fields in that document array. The file structure looks like this, { 'name':'xxxxx', 'comments':[ {comment: 'xxxxx', 'commentDate':'yyyy-MM-dd HH:mm:ss', 'id':1}, {comment: 'xxxxx',

How to sort an ElasticSearch index using a field in an array?

Isuru Pathirana I need to sort documents in elastic index using fields in that document array. The file structure looks like this, { 'name':'xxxxx', 'comments':[ {comment: 'xxxxx', 'commentDate':'yyyy-MM-dd HH:mm:ss', 'id':1}, {comment: 'xxxxx',

How to sort an ElasticSearch index using a field in an array?

Isuru Pathirana I need to sort documents in elastic index using fields in that document array. The file structure looks like this, { 'name':'xxxxx', 'comments':[ {comment: 'xxxxx', 'commentDate':'yyyy-MM-dd HH:mm:ss', 'id':1}, {comment: 'xxxxx',

How to sort an ElasticSearch index using a field in an array?

Isuru Pathirana I need to sort documents in elastic index using fields in that document array. The file structure looks like this, { 'name':'xxxxx', 'comments':[ {comment: 'xxxxx', 'commentDate':'yyyy-MM-dd HH:mm:ss', 'id':1}, {comment: 'xxxxx',

How to issue raw query with Java client in Elasticsearch?

Jane Wayne I found a SO post on how to get random records from ElasticSearch in random order and pagination from Elasticsearch . curl -XGET 'localhost:9200/_search' -d '{ "query": { "function_score": { "query": { "match_all": {} },

How to issue raw query with Java client in Elasticsearch?

Jane Wayne I found a SO post on how to get random records from ElasticSearch in random order and pagination from Elasticsearch . curl -XGET 'localhost:9200/_search' -d '{ "query": { "function_score": { "query": { "match_all": {} },