Запрос Elasticsearch для возврата всех записей

Сама спецификация C ++ (старая версия, но достаточно хорошая для этого) оставляет это открытым.

Существует четыре знаковых целочисленных типа: 'signed char', 'short int', 'int' и 'long int'. В этом списке каждый тип содержит как минимум столько же памяти, сколько и предшествующие ему в списке. Plain ints имеют естественный размер, предложенный архитектурой среды исполнения *;

[Сноска: достаточно большой, чтобы содержать любое значение в диапазоне INT_MIN и INT_MAX, как определено в заголовке . --- end foonote]

blockquote>

439
задан Aminah Nuraini 24 April 2016 в 00:46
поделиться

3 ответа

Для Elasticsearch 6.x

Запрос: GET /foo/_search?pretty=true

Ответ: В Hits-> total укажите количество документов

    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 1001,
        "max_score": 1,
        "hits": [
          {
3
ответ дан Sunder R 24 April 2016 в 00:46
поделиться
Параметр

size увеличивает количество отображаемых обращений со значения по умолчанию (10) до 500.

http://localhost:9200/[indexName]/_search?pretty=true&size=500&q=*:*

Измените с шаг за шагом, чтобы получить все данные.

http://localhost:9200/[indexName]/_search?size=500&from=0
3
ответ дан Prasanna Jathan 24 April 2016 в 00:46
поделиться

Это лучшее решение, которое я нашел с помощью клиента Python

  # Initialize the scroll
  page = es.search(
  index = 'yourIndex',
  doc_type = 'yourType',
  scroll = '2m',
  search_type = 'scan',
  size = 1000,
  body = {
    # Your query's body
    })
  sid = page['_scroll_id']
  scroll_size = page['hits']['total']

  # Start scrolling
  while (scroll_size > 0):
    print "Scrolling..."
    page = es.scroll(scroll_id = sid, scroll = '2m')
    # Update the scroll ID
    sid = page['_scroll_id']
    # Get the number of results that we returned in the last scroll
    scroll_size = len(page['hits']['hits'])
    print "scroll size: " + str(scroll_size)
    # Do something with the obtained page

https://gist.github.com/drorata/146ce50807d16fd4a6aa

Использование Java-клиента

import static org.elasticsearch.index.query.QueryBuilders.*;

QueryBuilder qb = termQuery("multi", "test");

SearchResponse scrollResp = client.prepareSearch(test)
        .addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
        .setScroll(new TimeValue(60000))
        .setQuery(qb)
        .setSize(100).execute().actionGet(); //100 hits per shard will be returned for each scroll
//Scroll until no hits are returned
do {
    for (SearchHit hit : scrollResp.getHits().getHits()) {
        //Handle the hit...
    }

    scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
} while(scrollResp.getHits().getHits().length != 0); // Zero hits mark the end of the scroll and the while loop.

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-scrolling.html

17
ответ дан Mark Rotteveel 24 April 2016 в 00:46
поделиться
Другие вопросы по тегам:

Похожие вопросы: