zoukankan      html  css  js  c++  java
  • elasticsearch 分页滚动搜索结果 scroll

    目的

    scroll用于获取大批量数据。由于elasticsearch获取文档数量有限制,所以需要使用scroll

    NEST

    scrolling-documents

    var searchResponse = client.Search<PostComment>(s => s
        .Index("post_comments")
        .Scroll("10s")
        .Size(100)
        .Query(q => q
            .Match(m => m
                .Field(f => f.Content)
                .Query("text")
                )
            )
        );
    
    List<PostComment> list = new List<PostComment>();
    while (searchResponse.Documents.Any())
    {
        list.AddRange(searchResponse.Documents);
        searchResponse = client.Scroll<PostComment>("10s", searchResponse.ScrollId);
    }
    
    Console.WriteLine(list.Count);
    

    HTTP

    第一次请求

    POST http://localhost:9200/post_comments/_search?typed_keys=true&scroll=10s HTTP/1.1
    Content-Type: application/json
    
    {
      "query": { "match": { "content": { "query": "text" } } },
      "size": 100
    }
    

    后续的多次请求

    POST http://localhost:9200/_search/scroll HTTP/1.1
    Content-Type: application/json
    
    {
      "scroll": "10s",
      "scroll_id": "FGluY2x1ZGVfY29udGV4dF91dWlkDXF1ZXJ5QW5kRmV0Y2gBFEpvYm9oblVCUFFkMXN4Q3hNbTQzAAAAAAAAAA0WcV80QUZCRmZUSDJlV2RzZGo3anFvZw=="
    }
    
  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    iOS
    九、原始套接字
    八、Linux下的网络服务器模型
    七、TCP/IP协议
    六、高级套接字函数
    五、用户数据报传输(UDP)
  • 原文地址:https://www.cnblogs.com/naergaga/p/13913570.html
Copyright © 2011-2022 走看看