Tenho usado "scroll" para obter sequências de dados de um índice ES (v 8.6.2) em Python.
Por vários motivos, quero mudar para fazer reqwest
solicitações em Rust (PyO3) em vez de requests
solicitações em Python. Meu primeiro pedido é assim:
let es_url = "https://localhost:9500"; // ES server is using this port
let data = json!({
"size": 100,
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": [
{
"term": {
"ldoc_type": "docx_doc"
}
}
]
}
},
});
let data_string = serde_json::to_string(&data).unwrap();
let url = format!("{es_url}/{}/_search?scroll=1m", INDEX_NAME.read().unwrap());
let send_result = reqwest_client
.post(url)
.header("Content-type", "application/json")
.body(data_string)
.basic_auth("mike12", Some("mike12"))
.send();
let response = match send_result {
Ok(response) => response,
Err(e) => {
error!("SEND error was {}", e);
return false
},
};
let text = match response.text() {
Ok(text) => text,
Err(e) => {
error!("TEXT error was {}", e);
return false
},
};
let json_hashmap: HashMap<String, Value> = serde_json::from_str(&text).unwrap();
let scroll_id = &json_hashmap["_scroll_id"];
let scroll_id_str = scroll_id.to_string();
let scroll_id_str = rem_first_and_last(&scroll_id_str); // strip "\"" either side
info!("|{:#?}| type {}", scroll_id_str, utilities::str_type_of(&scroll_id_str));
... isso mostra o &str
"ID de rolagem" retornado. Um exemplo típico é:
"=="
... isso é estranho, porque essa string de ID é cerca de 4 vezes maior que a string de ID que recebo quando uso Python. Mas a string acima, embora pareça ter um certo caráter repetitivo, não é na verdade uma repetição de uma string menor.
Depois disso, para fazer solicitações repetidas para obter mais lotes de 100 acessos, faço o seguinte:
let mut n_loops = 0;
loop {
n_loops += 1;
let data = json!({
"scroll": "1m",
"scroll_id": scroll_id_str,
});
let data_string = serde_json::to_string(&data).unwrap();
let url = format!("{es_url}/_search?scroll");
let send_result = reqwest_client
.post(url)
.header("Content-type", "application/json")
.body(data_string)
.basic_auth("mike12", Some("mike12"))
.send();
let response = match send_result {
Ok(response) => response,
Err(e) => {
error!("SEND error was {}", e);
return false
},
};
info!("response {:?} type {}", response, utilities::str_type_of(&response));
let response_status = response.status();
... é aqui que recebo 400, "Solicitação incorreta". Minha suspeita inicial é que o ID do pergaminho está errado. Em Python, as solicitações equivalentes de "follow-on" "scroll" funcionam bem.
Na sua segunda chamada, o URL está errado. Em vez disso
deveria ser isso