src/elastic-connection.c
int elastic_connection_search_scroll(struct elastic_connection *conn,
                              pool_t pool, string_t *query,
                              struct fts_result *result_r)
{
    FUNC_START();
    static const char *SCROLL_TIMEOUT = "7s";
    const char *path = NULL;

    if (conn == NULL || query == NULL || result_r == NULL) {
        i_error("fts_elastic: critical error during search scroll");
        return -1;
    }

    i_zero(conn->ctx);
    i_assert(conn->ctx != NULL);
    conn->ctx->pool = pool;
    conn->ctx->result = result_r;
    conn->ctx->found = 0;
    conn->post_type = ELASTIC_POST_TYPE_SEARCH;

	i_free_and_null(conn->http_failure);
    json_tokener_reset(conn->tok);

    path = t_strconcat(conn->http_base_path, "_search?routing=", conn->username,
                        "&scroll=", SCROLL_TIMEOUT, NULL);
    elastic_connection_post(conn, path, query);

    if (conn->ctx->scroll_id == NULL) {
        i_error("fts_elastic: _scroll_id not found in scroll response");
        return 0;
    }

    /* TODO: strip index (last segment) from path to allow elastic behind proxy */
    path = "/_search/scroll";
    while (conn->ctx->found >= 9998) {
        conn->ctx->found = 0;
        str_truncate(query, 0);
        str_printfa(query, "{\"scroll\":\"%s\", \"scroll_id\":\"%s\"}",
                            SCROLL_TIMEOUT,
                            conn->ctx->scroll_id);
        elastic_connection_post(conn, path, query);
    }
    /* DELETE search scroll context */
    conn->post_type = ELASTIC_POST_TYPE_DELETE;
    str_truncate(query, 0);
    str_printfa(query, "{\"scroll_id\":\"%s\"}", conn->ctx->scroll_id);
    elastic_connection_post(conn, path, query);

    if (conn->request_status < 0)
        return -1;

    FUNC_END_RET_INT(conn->ctx->found);
    return conn->ctx->found;
}
/* Performs elastic search query with scroll
 * parses json response
 * and fills fts_result
 */
Performs elastic search query with scroll
parses json response
and fills fts_result
Performs elastic search query with scroll parses json response and fills fts_result
int elastic_connection_search_scroll(struct elastic_connection *conn,
                              pool_t pool, string_t *query,
                              struct fts_result *result_r)
{
    FUNC_START();
    static const char *SCROLL_TIMEOUT = "7s";
    const char *path = NULL;
    if (conn == NULL || query == NULL || result_r == NULL) {
        i_error("fts_elastic: critical error during search scroll");
        return -1;
    }
    i_zero(conn->ctx);
    i_assert(conn->ctx != NULL);
    conn->ctx->pool = pool;
    conn->ctx->result = result_r;
    conn->ctx->found = 0;
    conn->post_type = ELASTIC_POST_TYPE_SEARCH;
	i_free_and_null(conn->http_failure);
    json_tokener_reset(conn->tok);
    path = t_strconcat(conn->http_base_path, "_search?routing=", conn->username,
                        "&scroll=", SCROLL_TIMEOUT, NULL);
    elastic_connection_post(conn, path, query);
    if (conn->ctx->scroll_id == NULL) {
        i_error("fts_elastic: _scroll_id not found in scroll response");
        return 0;
    }
    path = "/_search/scroll";
    while (conn->ctx->found >= 9998) {
        conn->ctx->found = 0;
        str_truncate(query, 0);
        str_printfa(query, "{\"scroll\":\"%s\", \"scroll_id\":\"%s\"}",
                            SCROLL_TIMEOUT,
                            conn->ctx->scroll_id);
        elastic_connection_post(conn, path, query);
    }
    conn->post_type = ELASTIC_POST_TYPE_DELETE;
    str_truncate(query, 0);
    str_printfa(query, "{\"scroll_id\":\"%s\"}", conn->ctx->scroll_id);
    elastic_connection_post(conn, path, query);
    if (conn->request_status < 0)
        return -1;
    FUNC_END_RET_INT(conn->ctx->found);
    return conn->ctx->found;
}
int elastic_connection_search_scroll ( struct elastic_connection * conn , pool_t pool , string_t * query , struct fts_result * result_r ) { FUNC_START ( ) ; static const char * SCROLL_TIMEOUT = " " ; const char * path = NULL ; if ( conn == NULL || query == NULL || result_r == NULL ) { i_error ( " " ) ; return -1 ; } i_zero ( conn -> ctx ) ; i_assert ( conn -> ctx != NULL ) ; conn -> ctx -> pool = pool ; conn -> ctx -> result = result_r ; conn -> ctx -> found = 0 ; conn -> post_type = ELASTIC_POST_TYPE_SEARCH ; i_free_and_null ( conn -> http_failure ) ; json_tokener_reset ( conn -> tok ) ; path = t_strconcat ( conn -> http_base_path , " " , conn -> username , " " , SCROLL_TIMEOUT , NULL ) ; elastic_connection_post ( conn , path , query ) ; if ( conn -> ctx -> scroll_id == NULL ) { i_error ( " " ) ; return 0 ; } path = " " ; while ( conn -> ctx -> found >= 9998 ) { conn -> ctx -> found = 0 ; str_truncate ( query , 0 ) ; str_printfa ( query , " \" \" \" \" \" \" \" \" " , SCROLL_TIMEOUT , conn -> ctx -> scroll_id ) ; elastic_connection_post ( conn , path , query ) ; } conn -> post_type = ELASTIC_POST_TYPE_DELETE ; str_truncate ( query , 0 ) ; str_printfa ( query , " \" \" \" \" " , conn -> ctx -> scroll_id ) ; elastic_connection_post ( conn , path , query ) ; if ( conn -> request_status < 0 ) return -1 ; FUNC_END_RET_INT ( conn -> ctx -> found ) ; return conn -> ctx -> found ; }
Performs elastic search query with scroll
 parses json response
 and fills fts_result
Performs elastic search query with scroll parses json response and fills fts_result
/* TODO: strip index (last segment) from path to allow elastic behind proxy */ /* DELETE search scroll context */